gpt4 book ai didi

c# - 如何从数据表中删除一行?

转载 作者:行者123 更新时间:2023-11-30 20:59:55 27 4
gpt4 key购买 nike

如何从数据表中删除一行_假设我的数据表中有 12 行,我需要使用特定的行值删除其中的一行..

数据表:

Field Name | Field Type 
------------------------
FirstName | Text box
|
LastName | Text box

我需要从表本身中删除选定的行使用下面的代码片段我可以检索 FirstName

string value = (string)selectedRows[i].Cells[0].Value;
Console.WriteLine(outdex);

但是如何从数据表中删除呢

谁能帮帮我吗?

最佳答案

根据 OP 的其他问题,他想从 DataGridView 中获取选定的行,并从临时的 DataTable 中删除该行。

//Get the row that is selected
DataGridViewRow dr = selectedRows.Cast<DataGridViewRow>().FirstOrDefault();
//Your temp DataTable
DataTable dtTemp = new DataTable();
//If there is a row selected
if (dr != null)
{
var rowToRemove = dtTemp.Rows.Cast<DataRow>().FirstOrDefault(row => row[0] == dr.Cells[0].Value);
if (rowToRemove != null)
dtTemp.Rows.Remove(rowToRemove);
}

关于c# - 如何从数据表中删除一行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15249056/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com