I am retriving data from a csv which is comma separated file and all the columns at the first time are represented as
string type. But I want to convert a specific column, when I am retriving the data to
int to be available to sort it.
I tried the following when I am loading the rows,
dr = dt.NewRow();
dr.ItemArray = sLine.Split('|');
if (dt.Columns.Contains('ID'))
{ dt.Rows.Add(dr, typeof(int)); }
else
{ dt.Rows.Add(dr); }
But is not working; when I try to sort the datatable using a dataview is still getting it as a
string...
Tried this too using a DataView from the DataTable,
DataView dv1 = new DataView(dt);
DataView dv2 = new DataView(dt);
int obj;
for ( int x= 0; x<dt.Rows.Count; x++)
{
int.TryParse(dv1[x][0].ToString(), out obj);
int.TryParse(dv2[x][0].ToString(), out obj);
}
dv1.Sort = "ItemNo ASC";
dv2.Sort = "ItemNo DESC";
but if I use MeesageBox.Show(dv1[0][0].ToString()); the data is in string is giving me, 1, 10, 100 an so on instead of 1, 2, 3 ...:confused: