再请教DataTable的InputRow时怎么控制自动增加列的问题 天呢,终于有人回复,不管怎么样,超级感谢就是我的DataTable中的第一列设为了自动增加,我在DataTable中复制其中的一行,怎么样达到既能够复制数据,又能够让自动增加的行继续自动增加而不是复制原行的该列的数据。急啊,请大虾们不吝赐教 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 DataTable dt = Bind_Notice(); DataColumn col = new DataColumn("NO", typeof(Int32)); col.AutoIncrement = true; col.AutoIncrementSeed = 1; col.AutoIncrementStep = 1; dt.Columns.Add(col);Top这样设置DataTable的自增列再把数据复制过去,自增列的值应该是自动增加吧 DataTable dt = ds.Tables["ATABZON"]; dt.Rows.Add(GetDataRow(dt,0)); private DataRow GetDataRow(DataTable dt, Int32 iRow) { DataRow dr = dt.NewRow(); for (int i = 0; i < dt.Columns.Count; i++) { if (!dt.Columns[i].AutoIncrement) { dr[i] = dt.Rows[iRow][i]; } } return dr; } int rowID = dt.Rows.Count*5; DataRow drNew = dt.Rows[0]);drNew[0] = rowID;dt.Rows.Add(drNew.ItemArray); 求一个可以在线播放 avi 的播放器 用c#如何在记事本中添加“工具栏”功能 c#关于数据库更新的问题 处理时间的,前辈请赐教. 散分,求一段调试过的编辑datagridview的代码!! 怎样利用两个查询结果继续查询? 请问:在WinForm中,如何嵌套Excel? 一个关于抽象类的选择题,大家看看答案是什么? 热帖:不知道BILL的.NET能生存多久? C#引用静态DLL操作出错,这是什么原因?? 怎样在c#中调用MapX控件?修改*.tab文件的表结构,给tab文件增加新列并保存到数据库?? 用DataSet.Merge 更新DataSet怎么无效呀?
DataColumn col = new DataColumn("NO", typeof(Int32));
col.AutoIncrement = true;
col.AutoIncrementSeed = 1;
col.AutoIncrementStep = 1;
dt.Columns.Add(col);Top
这样设置DataTable的自增列
再把数据复制过去,自增列的值应该是自动增加吧
dt.Rows.Add(GetDataRow(dt,0));
private DataRow GetDataRow(DataTable dt, Int32 iRow)
{
DataRow dr = dt.NewRow();
for (int i = 0; i < dt.Columns.Count; i++)
{
if (!dt.Columns[i].AutoIncrement)
{
dr[i] = dt.Rows[iRow][i];
}
}
return dr;
}
DataRow drNew = dt.Rows[0]);
drNew[0] = rowID;
dt.Rows.Add(drNew.ItemArray);