下面是一个代码,Visual Studio引发了WHERE附近存在语法错误的错误。
SqlCommand cmd2 = new SqlCommand("insert into courses(t_id_fk) values('" + valu3 + "') where c_id=@dr1 ", con);
cmd2.CommandType = CommandType.Text;
cmd2.Parameters.Add("@dr1", SqlDbType.Int);
cmd2.Parameters["@dr1"].Value = d1;
cmd2.ExecuteNonQuery();
con.Close();
答案 0 :(得分:4)
发件人:强>
"insert into courses(t_id_fk) values('" + valu3 + "') where c_id=@dr1 "
以强>
"insert into courses(t_id_fk) values('" + valu3 + "')"
但如果上面给出的样本是update
,那么:
"update courses set t_id_fk = '" + valu3 + "' where c_id=@dr1"