Create a DataTable from a CSV string (also from a file ofcourse):
public DataTable GetTable(string csv, params string[] header)
{
    var table = new DataTable();

    foreach (var column in header)
    {
        table.Columns.Add(column);
    }

    foreach (var line in csv.Split('\n'))
    {
        var dr = table.NewRow();
	dr.ItemArray = line.Split(',');
	table.Rows.Add(dr);
    }

    return table;
}

Last edited Jul 27, 2011 at 6:56 PM by teoarch, version 1

Comments

No comments yet.