/// <summary> /// This method takes a csv string (comma separated) and turns into a DataTable. /// </summary> /// <param name="csvString">The CSV string (comma separated).</param> /// <param name="tableName">Name of the table.</param> /// <returns></returns> public static DataTable CsvToTable(string csvString, string tableName) { var dtResult = new DataTable(); dtResult.TableName = tableName; using (var csv = new CachedCsvReader(new StringReader(csvString), true)) { string[] headers = csv.GetFieldHeaders(); foreach (string header in headers) dtResult.Columns.Add(header, typeof (string)); while (csv.ReadNextRecord()) { var newRow = dtResult.NewRow(); for (int columnNumber = 0; columnNumber < headers.GetLongLength(0); columnNumber++) newRow[columnNumber] = csv[columnNumber]; dtResult.Rows.Add(newRow); } } return dtResult; }
/// <summary> /// Initializes a new instance of the CsvBindingList class. /// </summary> /// <param name="csv"></param> public CsvBindingList(CachedCsvReader csv) { _csv = csv; _count = -1; _direction = ListSortDirection.Ascending; }