0

I am having an error using the following code,

DataView dtView = new DataView(dt);
columname = "ItemNo";
Cond procedure = Cond.checknum; //I had a public enum Cond { checknum, checkspace }
procedure.Equals(null); //Null because I am changing the procedure below in the program           
List<string> Mapcol = new List<string>(); 
foreach (string cols in dt.Columns)
{ Mapcol.Add(cols); } 
dtView.Sort = Mapcol.Contains(columname)+ " ASC";

I am retriving data from a .csv and is already at the DataTable called dt... But I am unable to pass the columns to the ColumnMap list...
Error = Unable to cast object of type 'System.Data.DataColumn' to type 'System.String'.

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by Momerath
0

dt.Columns returns an System.Data.DataColumn IEnumerable, but you are trying to force it to be a string (line 6). Use foreach (Column cols in dt.Columns) instead

0

dt.Columns returns an System.Data.DataColumn IEnumerable, but you are trying to force it to be a string (line 6). Use foreach (Column cols in dt.Columns) instead

I tried that but, "The type namespace 'Column' could not be found..." What I am missing?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.