LOOK~~~LOOK~~~~...thank you!!
SqlConnection con = DB.CreateConn();
con.Open();
string sqlstr0 = "delete from Teacher_course where Teacher_course.Teacher_id='" + Gv_teach.DataKeys[e.RowIndex].Value.ToString() + "'";
string sqlstr1 = "delete from Teacher where Teacher_id='"+Gv_teach.DataKeys[e.RowIndex].Value.ToString()+"'";
SqlCommand sqlcom0 = new SqlCommand(sqlstr0, con);
sqlcom0.ExecuteNonQuery();
SqlCommand sqlcom1 = new SqlCommand(sqlstr1, con);
sqlcom1.ExecuteNonQuery();
try
{
sqlcom1.ExecuteNonQuery();
Lbl_note.Text = "删除成功";
Lbl_note.Style["color"]="green";
}
catch (SqlException)
{
Lbl_note.Text = "删除失败";
Lbl_note.Style["color"] = "red";
}
sqlcom0.Connection.Close();
sqlcom1.Connection.Close();
St_BindGridView();
多表删除程序与各位讨论一下,能删除但不会执行try语句.有高人指点哈就好了.