在asp投票代码中关于sql语句的问题!!!

来源:百度知道 编辑:UC知道 时间:2024/09/23 10:53:21
protected void btnVote_Click(object sender, EventArgs e)
{
SqlConnection con = DB.createConnection();
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText ="uqdate voteDetails set voteNum=voteNum+1 where voteID="+voteID+"and voteDetailsID="+this .rBtnItems .SelectedValue .ToString ();
cmd.ExecuteNonQuery();
con.Close();
}
系统说cmd.ExecuteNonQuery执行时在 '='附近有语法错误!
请高人帮我解答谢谢了!

确定这些值的类型都是一样的

voteDetailsID="+this .rBtnItems .SelectedValue .ToString ();
字符串要加引号
数字不用加引号
voteDetailsID=获取的数字类型
this .rBtnItems .SelectedValue .ToString ()这个是字符串类型
所以会出错

voteID="+voteID+"and and前加空格或改为voteID=‘"+voteID+"’and

and前加空格