protected void GridView2_RowCommand(Object sender,GridViewCommandEventArgs e)
{
if (e.CommandName == "exit")
{
int index = Convert.ToInt32(e.CommandArgument);
DataKey key = GridView1.DataKeys[index];
string stuID = GridView2.DataKeys[index].Values[0].ToString().Trim();
string courceID = GridView2.DataKeys[index].Values[0].ToString().Trim();
string teaID = GridView1.DataKeys[index].Values[1].ToString().Trim();
string userName = Session["userName"].ToString();
string connStr = ConfigurationManager.ConnectionStrings["ConnectionStrings"].ConnectionString;
string sqlStr = "delete from Elect where stuID='" + userName + "' and courID='" + courceID + "' and teaID='" + teaID + "'";
}
try
{
SqlConnection conn = new SqlConnection(connStr); //报错没有定义connStr
if (conn.State.ToString() == "Close")
conn.Open();
SqlCommand comm = new SqlCommand(sqlStr, conn); //报错没有定义sqlStr
comm.ExecuteNonQuery();
comm.Dispose();
if (conn.State.ToString() == "Open")
conn.Close();
}
catch (System.Exception ex)
{
Response.Write("DataBase failed," + ex.Message);
}
}