Adding new row to datatable's top

2019-03-22 12:52发布

When we use datatable.newrow command, a new empty row added to bottom of rows. However I want newrow to added to top of datatable. How can I make it?

3条回答
我欲成王,谁敢阻挡
2楼-- · 2019-03-22 13:08

Here is the best example to add row in table

DataRow newRow = myDataTable.NewRow();
newRow[0] = "0";
newRow[1] = "Select one";
myDataTable.Rows.InsertAt(newRow, 0);

It's set the row on first

查看更多
萌系小妹纸
3楼-- · 2019-03-22 13:09

You use the NewRow to create a row with the same columns. To actually get it into the DataTable, you've got to do

myDataTable.Rows.InsertAt(myDataRow, 0);

Where 0 is the index you want to insert it at.

查看更多
聊天终结者
4楼-- · 2019-03-22 13:18

This One is Wrong

myDataTable.Rows.InsertAt(0,myDataRow); 

Please use the below line instead of that

myDataTable.Rows.InsertAt(myDataRow,0);
查看更多
登录 后发表回答