【问题标题】:MySQL, C#, You have an error in your SQL syntaxMySQL,C#,您的 SQL 语法有错误
【发布时间】:2015-05-09 13:39:02
【问题描述】:

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

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);
        }

每次出现错误:

“您的 SQL 语法有错误;请查看手册 对应于您的 MySQL 服务器版本,以便使用正确的语法 靠近 'IF p1c='0' THEN SET p1c='1' where Eid='123456789" at line 1"

IF”和“THEN”可能有问题?

【问题讨论】:

    标签: c# mysql sql syntax


    【解决方案1】:

    你不需要if,它可以在哪里

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

    【讨论】:

    • 啊@SamiKuhmonen 修复了它。
    猜你喜欢
    • 1970-01-01
    • 2013-02-01
    • 1970-01-01
    • 2012-10-10
    • 1970-01-01
    • 2014-10-25
    • 2019-12-03
    • 2016-02-16
    • 1970-01-01
    相关资源
    最近更新 更多