各位帮我看看为什么SQL更新不成功啊??
protected void Button1_Click(object sender, EventArgs e)
{
string sqltr = "Server=.;User ID=sa;Pwd=123;DataBase=student";
string category = DropDownList1.SelectedValue;
string admin = DropDownList2.SelectedValue;
string group = DropDownList3.SelectedValue;
string priority = DropDownList4.SelectedValue;
string summary = TextBox2.Text;
string description = TextBox3.Text;
string status = DropDownList5.SelectedValue;
string b = TextBox4.Text.ToString();
SqlConnection connection = new SqlConnection(sqltr);
SqlCommand command;
string sql = string.Format("update bug set category='{0}',admin='{1}',[group]='{2}',priority='{3}',summary='{4}',description='{5}',status='{6}'where ID='{7}'", category, admin, group, priority, summary, description, status, b);
connection.Open();
command = new SqlCommand(sql, connection);
int count = command.ExecuteNonQuery();
if (count > 0)
{
ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>alert('修改成功!')</script>");
}
else
{
ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>alert('添加成功!')</script>");
}
connection.Close();
}
[解决办法]
如无提示,那就考虑SQL的参数是否正确
[解决办法]
查看一下connection里的UpdateCommand对象是否被创建了