【发布时间】:2014-02-27 07:14:58
【问题描述】:
为什么这段代码不删除行并显示错误信息
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
try
{
String connectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(connectionString);
SqlCommand cmd=new SqlCommand("DELETE from [course] where cid ('"+cids.Text+"')",con);
con.Open();
cmd.ExecuteNonQuery();
Response.Redirect("done.aspx");
con.Close();
}
catch (SqlException)
{ Label1.Text = "error";
}
}
【问题讨论】:
-
它显示什么错误信息? (提示:将
catch(SqlException)更改为catch(SqlException e)并发布e的值) -
我怀疑你的 SQL 有点生疏了。也许您应该查阅手册:dev.mysql.com/doc/refman/5.7/en/delete.html