0

I have a DataTable dt1 that contains this columns : PRODUCT_ID,MIN_VALUE,MAX_VALUE,AMOUNT and another DataTable dt2 that contains this columns : ID,MIN,MAX,POINT_TO_ADD

dt1 contains multiple rows that I want to copy them to dt2 how can I do that ?

4

2 回答 2

1

try this

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);
}
于 2013-11-07T09:18:01.720 回答
0

Try this:

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);
}
于 2013-11-07T09:24:51.737 回答