在特定行插入datarow值

时间:2012-02-24 05:22:17

标签: c# asp.net datarow

我想在datatable特定行中插入datarow值。我有一个数据表的值,然后我想用c#覆盖特定的行值。

我的部分代码ID在这里:

   for (int j = 0; j < DT.Rows.Count; j++)
            {
                row = DT2.NewRow();

                row["Employee ID"] = Convert.ToString(DS.Rows[j]["fldempid"]);
                row["Employee Name"] = Convert.ToString(DS.Rows[j]["fldempname"]);
                string leavehstry = Convert.ToString(DS.Rows[j]["fldleavehistory"]);
                string[] textarray1 = leavehstry.Split('-');
                char[] delimiterChars1 = { ':' };
                for (int i = 1; i <= textarray1.Length - 1; i++)
                {
                    string[] words = textarray1[i - 1].Split(delimiterChars1);
                    string value = words[0].ToString();
                    string value1 = words[1].ToString();
                    row[value] = value1;
                    ivalue = i;

                }
                //DT2.Rows[j].Delete(); //I want to insert (or) overwrite the row value at j th position. 
                //DT2.Rows.Add(row);
                //DT2.Rows[j].AcceptChanges();


            }

请帮我插入..

2 个答案:

答案 0 :(得分:1)

您可以使用InsertAt方法在指定索引位置的DataTable中插入DataRow。

你可以用这三个注释掉的行来代替:

DT2.InsertAt(row, j);

答案 1 :(得分:0)

如果EmployerID是唯一值,则将DataColumn“EmployerID”值与EmployerID进行比较,并使用for循环分配数据流值。

相关问题