我有DataTable dt1
,其中包含以下列:PRODUCT_ID,MIN_VALUE,MAX_VALUE,AMOUNT
以及包含此列的另一个DataTable dt2
:ID,MIN,MAX,POINT_TO_ADD
dt1包含多行我想将它们复制到dt2我该怎么做?
答案 0 :(得分:1)
试试这个
foreach (DataRow sourcerow in dt1.Rows)
{
DataRow destRow = dt2.NewRow();
destRow["ID"] = sourcerow["PRODUCT_ID"];
destRow["MIN"] = sourcerow["MIN_VALUE"];
destRow["MAX"] = sourcerow["MAX_VALUE"];
destRow["POINT_TO_ADD"] = sourcerow["AMOUNT"];
dt2.Rows.Add(destRow);
}
答案 1 :(得分:0)
试试这个:
for(int i=0;i<dt1.Rows.Count;i++){
DataRow dr = dt2.NewRow();
dr["ID"] = dt1.Rows[i]["PRODUCT_ID"];
dr["MIN"] = dt1.Rows[i]["MIN_VALUE"];
dr["MAX"] = dt1.Rows[i]["MAX_VALUE"];
dr["POINT_TO_ADD"] = dt1.Rows[i]["AMOUNT"];
dt2.Rows.Add(dr);
}