gpt4 book ai didi

c# - 在 DataTable 中查找一行

转载 作者:太空狗 更新时间:2023-10-30 00:08:08 25 4
gpt4 key购买 nike

我在 DataSet 中有一个表,我想使用唯一键在该表中搜索一行。

我的问题是:是否有任何方法可以让我在不使用循环的情况下找到这一行?

这是我使用 forech 循环编写的代码:

foreach (var myRow in myClass.ds.Tables["Editeur"].AsEnumerable())
{
if (newKeyWordAEditeurName == myRow[1] as String)
id_Editeur_Editeur = (int)myRow[0];
}

最佳答案

当然。您有 DataTable 的 Select 方法。从您的 DataSet 中获取表,并使用 Select 来获取它。

void Demo(DataSet ds)
{
DataTable dt = ds.Tables[0]; // refer to your table of interest within the DataSet

dt.Select("Field = 1"); // replace with your criteria as appropriate
}

关于c# - 在 DataTable 中查找一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12656526/

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