数据表更新问题 [英] DataTable Update Problem
问题描述
我有两个DataTables
一种是来自本地数据库(由存储过程填充),请说dt1
第二个来自远程(即来自服务器的数据库),请说dt2
两者具有相同的表和记录,但是同一列(称为可访问)记录的区别在于该列的某些记录具有不同的值
我想检查一下,如果datatable2accessible是NO,那么更新datatable1可以访问NO
我已经完成以下代码
I have two DataTables
One is from local database(Populated with Stored Procedure) let say dt1
Second one is coming from Remotely(ie From a server''s database) let say dt2
Both have same table and records,but difference is of one column (named Accessible) records is that some records of this column have different values
I want to apply a check that if datatable2 accessible is NO then update datatable1 accessible to NO
I have done folowing code
int i=0;
foreach (DataRow dtrow in dt2.Rows)
{
i++;
if (dtrow["Accessible"].ToString().ToUpper() == "NO")
{
dt1.Rows[i]["Accessible"] = "NO";
}
}
我如何检查Drow的特定行的值NO
How can i check on specific row of Drow for value NO
推荐答案
正如您所说的,两个表列都是相同的,并且我相信您的表可能有一个键.因此,当条件匹配时,请根据第二个表中的第一个表的键值选择行,然后更新该行.
谢谢
As you said both table columns are same and I believe your table may have a key. So when condition matched then select row based on key first table key value in second table then update the row.
Thanks,
这篇关于数据表更新问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!