string connstr = "Provider=Microsoft.Jet.OleDb.4.0;";
connstr += @"Data Source=GEARCNC.mdb";
OleDbConnection tempconn = null;
try
{
if (MessageBox.Show("确定删除这一项吗?", "confirm Message", MessageBoxButtons.OKCancel) == DialogResult.OK)
{
tempconn = new OleDbConnection(connstr);
OleDbDataAdapter GrindingWheelInformationDA = new OleDbDataAdapter("select * from GrindingWheelInformation order by 砂轮名称", tempconn);
DataSet ds = new DataSet();
GrindingWheelInformationDA.Fill(ds, "GrindingWheelInformation");
int hang = this.listView1.SelectedIndices[0];
DataRow dr = ds.Tables["GrindingWheelInformation"].Rows[hang];
dr.Delete();
OleDbCommandBuilder builder = new OleDbCommandBuilder(GrindingWheelInformationDA);
GrindingWheelInformationDA.Update(ds, "GrindingWheelInformation");//这边报错,提示数据库查询过于复杂
listView1.Items.Remove(listView1.SelectedItems[0]);
MessageBox.Show("删除完毕!!!");
}
}
catch (Exception ex)
{
MessageBox.Show("请选中一行需要删除的数据!");
}
finally
{
tempconn.Close();
}