我有像这样的SQL命令
SqlCommand cmd = new SqlCommand(
"IF NOT EXISTS(SELECT english from dic where english='"+e_word+"') " +
"Insert INTO dic VALUES('"+e_word+"',N'"+b_word+"') " +
"else " +
"UPDATE dic SET english='"+e_word+"',bangla=N'"+b_word+"' WHERE english='"+e_word+"'",con);
cmd.ExecuteNonQuery();
但我得到的错误就像
Incorrect syntax near 's'.
Incorrect syntax near 's'.
我该如何解决这个问题?????
答案 0 :(得分:4)
FTFY:
SqlCommand cmd = new SqlCommand(@"
IF NOT EXISTS(SELECT english from dic where english=@e_word)
Insert INTO dic (english, bangla) VALUES(@e_word,@b_word)
else UPDATE dic SET bangla=@b_word WHERE english=@e_word",con);
cmd.Parameters.AddWithValue("e_word", e_word);
cmd.Parameters.AddWithValue("b_word", b_word);
cmd.ExecuteNonQuery();
(实际上,我通常做的有点不同,但我不想重写整个事情)