#region 连接字符串
//string strcon = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\程序书籍软件\c#程序代码\access数据库操作\addressList.mdb"; //绝对路径
string strcon = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Environment.CurrentDirectory+"\\addressList.mdb"; //相对路径
#endregion
#region 删除
private void tsbDelete_Click(object sender, EventArgs e)
{
delete();
}
#endregion
#region 删除语句
private void delete()
{
try
{
int[] rowCount = this.gridView1.GetSelectedRows();
string strSql = "";
foreach (int i in rowCount)
{
this.gridView1.FocusedRowHandle = -1;
string strID = "";
strID = this.gridView1.GetRowCellValue(i, "ZMID").ToString();
strSql = "delete from new1 where ZMID=" + strID + ""; //注意where处没有单引号
}
OleDbConnection connet1 = new OleDbConnection(strcon);
connet1.Open();
OleDbCommand cmd = new OleDbCommand(strSql, connet1);
int a = cmd.ExecuteNonQuery();
connet1.Close();
if (a > 0)
{
MessageBox.Show("删除成功");
}
query();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}