MySQL,C#,您的SQL语法有错误

时间:2022-07-08 23:05:31

I don't know what is wrong in this code:

我不知道这段代码有什么问题:

C#:

string myConnection1 = "datasource=localhost;port=3306;username=root;password=root";
        string Query = "UPDATE private IF p1c='0' THEN SET p1c='1' where Eid='123456789' ;";
        MySqlConnection conDataBase = new MySqlConnection(myConnection1);
        MySqlCommand cmdDataBase = new MySqlCommand(Query, conDataBase);
        MySqlDataReader myReader1;
        try
        {
            conDataBase.Open();
            myReader1 = cmdDataBase.ExecuteReader();
            MessageBox.Show("Saved");

        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }

Every time I got error:

每次我收到错误:

"You have an error in your SQL syntax; chceck the manual that corresponds to your MySQL server version for the right syntax to use near 'IF p1c='0' THEN SET p1c='1' where Eid='123456789" at line 1"

“你的SQL语法有错误;选择与你的MySQL服务器版本相对应的手册,以便在'IF p1c ='0'附近使用正确的语法。然后在p1c ='1',其中Eid ='123456789”在第1行“

Maybe is problem with "IF" and "THEN"?

也许是“IF”和“那么”的问题?

1 个解决方案

#1


You do not need if, it could be in the where

你不需要,它可能在哪里

UPDATE private 
set  p1c='1' where Eid='123456789' and p1c='0';

#1


You do not need if, it could be in the where

你不需要,它可能在哪里

UPDATE private 
set  p1c='1' where Eid='123456789' and p1c='0';