如何用dataGridView来写以下代码?
private void button2_Click(object sender, EventArgs e){
if (dataGrid1[dataGrid1.CurrentCell] != null)
{
string sql = "select specialtyname from specialtyinfo where specialtyid=" + ds.Tables["specialty"].Rows[dataGrid1.CurrentCell.RowNumber][0].ToString().Trim() + "and specialtyid not in (select distinct specialtyinfo.specialtyid from classinfo inner join specialtyinfo on classinfo.specialtyname=specialtyinfo.specialtyname)";
OleDbCommand cmd = new OleDbCommand(sql, connection1);
OleDbDataReader dr;
dr = cmd.ExecuteReader();
if (!dr.Read())
{
MessageBox.Show("删除专业'" + ds.Tables["specialty"].Rows[dataGrid1.CurrentCell.RowNumber][1].ToString().Trim() + "'失败,请先删除与此专业相关的班级", "提示");
dr.Close();
}
else
{
dr.Close();
sql = "delete * from specialtyinfo where specialtyname not in (select distinct specialtyname from classinfo) and specialtyid=" + ds.Tables["specialty"].Rows[dataGrid1.CurrentCell.RowNumber][0].ToString().Trim();
= sql;
cmd.ExecuteNonQuery();
MessageBox.Show("删除专业'" + ds.Tables["specialty"].Rows[dataGrid1.CurrentCell.RowNumber][1].ToString().Trim() + "'成功", "提示");
}
}
}