[英]C# Dataset - Filling a datarow from another datatable with parameters
我是C#的新手,所以請忍受...
我有2個表的數據集:
我要執行的操作是更新“費用”表上的ID,其中“前提[PremNo]”等於“費用[PremNo]”。
到目前為止,我有一個遍歷所有行並對其進行更新的foreach,我只是不知道如何指定從何處進行更新
foreach (DataRow row in ds.Tables[1].Rows)
{
foreach (DataColumn ID in ds.Tables[1].Columns)
{
row["ID"] = **12345**;
}
}
我需要有人為12345位指向我。
ds.Tables [1]是成本,ds.Tables [0]是前提
任何幫助將不勝感激。
擔
嘗試這個..
var tblCost = ds.Tables[1];
var tblPremises = ds.Tables[0];
foreach (DataRow cost in tblCost.Rows)
{
var premRow = tblPremises.AsEnumerable().Where(row => row.Field<int>("PremNo") == cost.Field<int>("PremNo")).FirstOrDefault();
if (premRow != null)
cost["ID"] = premRow.Field<int>("ID");
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.