请教一下:
SqlCommandBuilder scb = new SqlCommandBuilder(adap);
dt = new DataTable();
dt.PrimaryKey = new DataColumn[] { dt.Columns["id"] }; //设了一下主键 .我表中也有主键!! adap.FillSchema(dt, SchemaType.Mapped); //我加了这个,也报这个错? adap.Fill(dt);然后我更新:
dt.Rows[i]["sendyorn"] = 1;
adap.Update(dt);
}然后就报错:错如下:
the UpdateCommand affected 0 of the expected 1 records???中文意思是:违反并发性: UpdateCommand 影响了预期 1 条记录中的 0 条
SqlCommandBuilder scb = new SqlCommandBuilder(adap);
dt = new DataTable();
dt.PrimaryKey = new DataColumn[] { dt.Columns["id"] }; //设了一下主键 .我表中也有主键!! adap.FillSchema(dt, SchemaType.Mapped); //我加了这个,也报这个错? adap.Fill(dt);然后我更新:
dt.Rows[i]["sendyorn"] = 1;
adap.Update(dt);
}然后就报错:错如下:
the UpdateCommand affected 0 of the expected 1 records???中文意思是:违反并发性: UpdateCommand 影响了预期 1 条记录中的 0 条
SqlDataAdapter myDataAdapter = new SqlDataAdapter(aSql, mSqlConnect);
SqlCommandBuilder cb = new SqlCommandBuilder(myDataAdapter);
cb.ConflictOption = ConflictOption.OverwriteChanges ;
cb.SetAllValues = true;
DataTable dt = new DataTable();
myDataAdapter.Fill(dt);
//修改
myDataAdapter.Update(dt);出现这个错误,是因为Adapter产生的update脚本不正确
可以调试时,查看myDataAdapter 的UpdateCommand 对应的TEXT
我的SELEct是:select top 10 id,name 不是*
或者:
There is no row at position 4数字是变的,不知是啥原因.
There is no row at position 15是另外一个问题建议你老老实实的开一个测试项目,按我写的先跑通再仔细比较区别
dt.AcceptChange();方法试一下