datatable sort method not working!
here is my datatable:
DataTable dttemp = new DataTable();
dttemp.Columns.Add(new DataColumn("position", typeof(string)));
dttemp.Columns.Add(new DataColumn("specimen", typeof(string)));
i 开发者_Go百科am sorting like this and then importing every row into a different datatable:
view = dttemp.DefaultView;
view.Sort = "position";
foreach (DataRow row in dttemp.Rows)
dt_final.ImportRow(row);
here are the two rows that it is supposed to sort however as you can see it is not sorting
D01 PAINCAL4
F01 PAINQC2
A01 PAINCAL1
C01 PAINCAL3
E01 PAINQC1
G01 PAINQC3
H01 PAINQC4
it is supposed to sort on the first column
what am i doing wrong?
foreach (DataRowView row in dttemp.DefaultView)
dt_final.ImportRow(row.Row);
You are showing the rows of the dataTable, the datatable itself is not sorted, you will want to iterate through the DataRowView
EDIT:
foreach (DataRowView drv in dv) // replace your vars
{
for (int i = 0; i < dv.Table.Columns.Count; i++)
Console.WriteLine(drv[i]);
}
精彩评论