private void button3_Click(object sender, System.EventArgs e)
{
if(this.txtId.Text =="")
{
MessageBox.Show("没有数据可以被删除","路灯信息",MessageBoxButtons.OK,MessageBoxIcon.Information  );
return;
}
string msg = "您确定要删除选定的记录吗?"; if(MessageBox.Show(msg, "路灯信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.No )
return ;
try
{
//连接到数据库
OleDbConnection myConn = new OleDbConnection (cwn) ;
myConn.Open () ;
string strDele = "DELETE FROM Lightinfo WHERE l_id = '" + this.txtId.Text +"'" ;
OleDbCommand myCommand = new OleDbCommand ( strDele , myConn ) ;
//从数据库中删除指定记录
myCommand.ExecuteNonQuery () ;
//从DataSet中删除指定记录
//this.dsT.Tables [ "road" ].Rows[mybind.Position] . Delete ( ) ;
//this.dsT.Tables [ "road" ] . AcceptChanges ( ) ;
dsT.Tables[0].Rows[dataGrid1.CurrentCell.RowNumber].Delete();
myConn.Close ( ) ;
}
catch ( Exception ed )
{
MessageBox.Show ( "删除记录错误信息: " + ed.ToString ( ) , "路灯信息",MessageBoxButtons.OK,MessageBoxIcon.Information  ) ;
}
}