ASP NET中Where子句附近的错误

时间:2017-06-08 02:45:15

标签: c# sql-server

下面是一个代码,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();

1 个答案:

答案 0 :(得分:4)

插入时删除where子句:

发件人:

"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"