首页 > 代码库 > c# datatable增加列并赋值

c# datatable增加列并赋值

DataView dv = DataObj.GetBmfzr("03").Tables[0].DefaultView;

dv.Sort = "bmbh";
DataTable dt = ds.Tables[0];
dt.Columns.Add("bkzz",typeof(string));
foreach (DataRow rs in dt.Rows)
{
string fzr = "";
DataRowView[] drv = dv.FindRows(new object[] { rs["bzh"].ToString() });
if (drv.Length > 0)
{
for (int n = 0; n <= drv.Length - 1; n++)
{
fzr += fzr == "" ? drv[n]["xm"].ToString() : "," + drv[n]["xm"].ToString();
}
}
rs["bkzz"] = fzr;
}