日期:2014-05-17 浏览次数:21122 次
private void btnDel_Click(object sender, EventArgs e)//删除
{
try
{
strSelect = "DELETE FROM " + BiaoMingID + " WHERE '红点名字'='" + redname + "'";
OpenAccess(strSelect, 2);//打开连接
string xuanze = "Select * from " + BiaoMingID;//BiaoMingID 里存着表的名字
adObj = new OleDbDataAdapter(xuanze, oleCon);
adObj.DeleteCommand = myCommand;//myCommand = new OleDbCommand(strSelect, oleCon);
adObj.Fill(mydataset, BiaoMingID);
DataTable mydatatable = mydataset.Tables[BiaoMingID];
if (mydatatable.Rows.Count != 0)//如果行的总数不等于0
{
for (int n = 0; n < mydatatable.Rows.Count; n++)
{
if (mydatatable.Rows[n][8].ToString() == (kongjian as Button).Name)
{
mydatatable.Rows[n].Delete();
adObj.Update(mydataset, BiaoMingID);//这个错误。。违反并发性: DeleteCommand 影响了预期 1 条记录中的 0 条。
mydataset.AcceptChanges();
MessageBox.Show("此记录删除成功");
&nbs