我在 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/