DataTable 操作,克隆,添加行

DataSet dt = rule.GetMyPayOrder(cid, uid);
int coutf = dt.Tables[0].Rows.Count;//父及数量
int couts = dt.Tables[1].Rows.Count;//子集数量
for (int i = 0; i < coutf; i++)
{

DataTable t=new DataTable();//子集
t = dt.Tables[1].Clone(); //克隆结构 Copy()复制全部

for (int j = 0; j < couts; j++)
{
if (dt.Tables[1].Rows[j]["PayID"].ToString().Equals(dt.Tables[0].Rows[i]["PayID"].ToString()))
{
t.ImportRow(dt.Tables[1].Rows[j]);
}
}
dt.Tables[0].Rows[i]["data"] = JsonHelper.ToJson(t, true);
}

原文地址:https://www.cnblogs.com/lucoo/p/5163871.html