开发者

datatable row deleting problem

开发者 https://www.devze.com 2023-01-25 07:05 出处:网络
There is a command to delete rows in datatable Delete(); But that is just deleting it is not shifting up the following rows like vector or arraylist.

There is a command to delete rows in datatable Delete();

But that is just deleting it is not shifting up the following rows like vector or arraylist.

For eg, there are 3 row开发者_运维技巧s in data table.

Row 1, Data 1

Row 2, Data 2

Row 3, Data 3.

IF i delete Row 2, it will be like

Row 1, Data 1

Row 2, RowStatus = Deleted

Row 3, Data 3

How can I move up Row 3 to Row 2???

I have a way but it is not the correct one.

My one is create a new datatable, clone it and move every row to that table by checking the row status for each row. Then clear the actual datatable, and copy back all the data from temporary datatable.

There must be a better way.. anyone??


You have to call AcceptChanges on the DataTable to commit the changes made. Doing this will remove the rows marked as Deleted. (Along with any other changes made to the DataTable)


The Delete method marks the row for deletion in the database, and does not actually remove it from the DataTable. The DataTable.Rows.Remove method will remove the row from the DataTable in memory in the way that you want.


Yes you have to use DataTable.AcceptChages() Method to reflect the changes to the DataTable.


Why you wanna move up the rows? Forgive my curiosity ;-)

0

精彩评论

暂无评论...
验证码 换一张
取 消