{
SqlConnection conn = new SqlConnection(connStr); if (conn.State.ToString() == "Closed") conn.Open();
SqlCommand comm = new SqlCommand(SqlStr, conn); comm.ExecuteNonQuery(); comm.Dispose();
if (conn.State.ToString() == "Open") conn.Close();
GridView1.EditIndex = -1; GridViewBind(); }
catch (Exception ex) {
Response.Write("数据库错误,错误原因:" + ex.Message); Response.End(); } }
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) {
string id = GridView1.DataKeys[e.RowIndex].Values[0].ToString(); string teaID = GridView1.DataKeys[e.RowIndex].Values[1].ToString();
string connStr = ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString; string SqlStr = "delete from Cource where courceID=" + id+" and teaID="+teaID;
try {
SqlConnection conn = new SqlConnection(connStr); if (conn.State.ToString() == "Closed") conn.Open();
SqlCommand comm = new SqlCommand(SqlStr, conn); comm.ExecuteNonQuery(); comm.Dispose();
if (conn.State.ToString() == "Open") conn.Close();
GridView1.EditIndex = -1; GridViewBind(); }
catch (Exception ex) {
Response.Write("数据库错误,错误原因:" + ex.Message);