C# 在特定行插入数据行值
我想在datatable的特定行中插入datarow值。我有一个带有值的数据表,然后我想用c#覆盖特定的行值 我的部分代码id在此:C# 在特定行插入数据行值,c#,asp.net,datarow,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"]);
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();
}
for(int j=0;j for(int i=1;i如果EmployerID是唯一的值,则将DataColumn“EmployerID”值与EmployerID进行比较,并使用for循环指定所需的datarow值。可以使用该方法在DataTable的指定索引位置插入datarow
您可以这样做来代替三行注释:
DT2.InsertAt(row, j);