怎样update datatable某一行的某一列数据?DataRow[] drExist =
datatable.Select(" GS_PLId='" + li.Name + "' AND GS_LId='" + txtCurrentLayId.Text + "' and GS_StartDate ='" + li.SubItems[2].Text.ToString().Trim() + "' ");更改找到这行的其中一列
datatable.Select(" GS_PLId='" + li.Name + "' AND GS_LId='" + txtCurrentLayId.Text + "' and GS_StartDate ='" + li.SubItems[2].Text.ToString().Trim() + "' ");更改找到这行的其中一列
dr.BeginEdit();
dr["XXX"] = XXXXX;
dr.EndEdit();
dt.AcceptChanges();
若是用SqlDataAdapter从数据库里读取了数据,然后fill进了table中,
则此时千万要注意,此时table中的各个DataColumn的类型已经确定,而此时
假如table中无数据(别想可以把其数据清空,我清空无论如何还是有问题,修改不了)。
修改列的数据类型代码如下:
DataColumn Column=table.Columns ["intime"];
Column.DataType =Type.GetType ("string");
table.AcceptChanges ();
在数据类型一致的情况下可以通过
DataRow row=table.Rows[i];
row.BeginEdit();
row["intime"]="4:05:06";
row.EndEdit();
table.AcceptChanges();这样来更改对应列的数据值。
Tag标签: 修改datatable中的单行或单列