数据表行删除问题

发布于 2024-10-02 16:05:55 字数 385 浏览 1 评论 0原文

有一个命令可以删除数据表中的行Delete();

但这只是删除它,而不是像向量或数组列表那样向上移动以下行。

例如,数据表中有3行。

第 1 行,数据 1

第 2 行,数据 2

第 3 行,数据 3。

如果我删除第 2 行,它将类似于

第 1 行,数据 1

第 2 行,行状态 = 已删除

第 3 行,数据 3

我怎样才能将第 3 行上移到第2行???

我有一个方法,但不是正确的方法。

我的方法是创建一个新的数据表,克隆它并通过检查每行的行状态将每一行移动到该表。然后清除实际数据表,并从临时数据表中复制回所有数据。

一定有更好的方法..有人吗?

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 rows 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??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

情泪▽动烟 2024-10-09 16:05:55

您必须在 DataTable 上调用 AcceptChanges提交所做的更改。执行此操作将删除标记为“已删除”的行。 (以及对数据表所做的任何其他更改)

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)

清风挽心 2024-10-09 16:05:55

Delete 方法在数据库中标记要删除的行,但实际上并不将其从 DataTable 中删除。
DataTable.Rows.Remove 方法将以您想要的方式从内存中的 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.

情独悲 2024-10-09 16:05:55

是的,您必须使用 DataTable.AcceptChaages() 方法来反映对 DataTable 的更改。

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

等往事风中吹 2024-10-09 16:05:55

为什么你想向上移动行数?请原谅我的好奇心;-)

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文