0

查询如下所示:

string query = "IF NOT EXISTS(
 SELECT * from clienti 
 where CodCliente=  ' " + id + " ' 
 AND NomeCliente= ' " + emri + " ' 
 AND RagioneSociale=' " + ragSoc + " ' 
 AND PartitaIVA=' " + piva + " ') 

Insert INTO clienti VALUES(
 ' " + id + 
 " ',' " + emri + 
 " ',' " + ragSoc + 
 " ',' " + piva + " ') 
 else 
  UPDATE clienti 
  SET(' " + id + " ',' " + emri + " ',' " + ragSoc + " ',' " + piva + " ')";

我只是不断遇到以下相同的问题:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IF NOT EXISTS(SELECT * from clienti where CodCliente= ' 1 ' AND NomeCliente= ' ' at line 1

4

2 回答 2

0

您在所有变量之前和之后连接空格。另外,确保所有变量都是字符串格式。

于 2013-04-19T21:16:58.737 回答
0

我认为您缺少THENandEND IF关键字。查看mysql手册

IF search_condition THEN statement_list
    [ELSEIF search_condition THEN statement_list] ...
    [ELSE statement_list]
END IF
于 2013-04-19T19:58:44.733 回答