我需要根据其他列值
更新VB.net中的数据表| Column_1 | Column_2 | Column_3 | ___________ ____________ ____________ | 2 | 1 | | ___________ ____________ ____________ | 5 | 3 | | ___________ ____________ ____________ | 4 | 2 | | ___________ ____________ ____________ | 1 | 7 | | ___________ ____________ ____________ | 8 | 9 | | ___________ ____________ ____________
我需要column1 value
5 ,我需要column 3
1 ,剩下的行应该为零。< / p>
我试过的是
Dim CandidateRow As DataRow
CandidateRow = datatable.select("Column_1" = & rbl.selectedvalue).FirstOrDefault ' datatable value here rbl.selected value would return 5
CandidateRow("Column_3") = 1
它没有更新Datatable。
那么可以做些什么呢?
答案 0 :(得分:3)
尝试下面的c#代码并将其转换为vb.net
foreach(DataRow row in table)
{
if(row["Column_1"]!=null and row["Column_1"].ToString()=="5")
{
row["Column_3"]=1;
}
else
{
row["Column_3"]=0;
}
}
//call AcceptChanges() to persist changes made.
table. AcceptChanges();