2015-05-09 56 views
-2

我不知道什么是错在此代码:的MySQL,C#,你有一个错误的SQL语法

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

每次我错误:

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

也许是 “IF” 和 “THEN” 的问题?

回答

2

你不需要if,也可能是在那里

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

一倍,在SQL命令 –

+1

啊@SamiKuhmonen固定它'设置SET'。 –

相关问题