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;
}

posted @ 2014-07-02 16:05  樱花飞落ll  阅读(8310)  评论(0编辑  收藏  举报