OleDbCommand myCommand = new OleDbCommand(); //oleDbConn是连接OleDbConnection if (this.oleDbConn.State==ConnectionState.Closed) this.oleDbConn.Open(); OleDbTransaction tr=this.oleDbConn.BeginTransaction(); myCommand.Connection =this.oleDbConn; myCommand.Transaction =tr; try { foreach (DataRow dr in bookset1.Tables["BookTab"].Rows) { if ((bool)dr["abc",DataRowVersion.Current]==true) { //假设表BookTab中字段bookID是主键 myCommand.CommandText="delete from BookTab where id="+dr["bookID"].ToString(); myCommand.ExecuteNonQuery(); } } tr.Commit(); } catch { tr.Rollback(); MessageBox.Show("提交错误"); } finally { this.oleDbConn.Close(); }
谢谢 dy_2000_abc(芝麻开门) 我复制下去研究研究
to dy_2000_abc(芝麻开门) 我用了你这段程序,倒是可以将选中的纪录从注册表里删掉。可是必须选中2个纪录以上这是为什么??我怎么也想不通。 我设置断点看了一下,如果选中一个它的(bool)dr["abc",DataRowVersion.Current]==false 如果选两个只能删掉第一个选中的选中的。老大帮帮我好么
//oleDbConn是连接OleDbConnection
if (this.oleDbConn.State==ConnectionState.Closed)
this.oleDbConn.Open();
OleDbTransaction tr=this.oleDbConn.BeginTransaction();
myCommand.Connection =this.oleDbConn;
myCommand.Transaction =tr;
try
{
foreach (DataRow dr in bookset1.Tables["BookTab"].Rows)
{
if ((bool)dr["abc",DataRowVersion.Current]==true)
{
//假设表BookTab中字段bookID是主键
myCommand.CommandText="delete from BookTab where id="+dr["bookID"].ToString();
myCommand.ExecuteNonQuery();
}
}
tr.Commit();
}
catch
{
tr.Rollback();
MessageBox.Show("提交错误");
}
finally
{
this.oleDbConn.Close();
}
dy_2000_abc(芝麻开门)
我复制下去研究研究
我用了你这段程序,倒是可以将选中的纪录从注册表里删掉。可是必须选中2个纪录以上这是为什么??我怎么也想不通。
我设置断点看了一下,如果选中一个它的(bool)dr["abc",DataRowVersion.Current]==false
如果选两个只能删掉第一个选中的选中的。老大帮帮我好么