c#代码中使用的自定义查询语法有什么问题?

本文关键字:语法 什么 问题 查询 自定义 代码 | 更新日期: 2023-09-27 18:10:00

查询如下:

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

c#代码中使用的自定义查询语法有什么问题?

我想你漏掉了THENEND IF关键字。查看mysql手册

IF search_condition THEN statement_list
    [ELSEIF search_condition THEN statement_list] ...
    [ELSE statement_list]
END IF

将所有变量前后的空格连接起来。此外,请确保所有变量都是字符串格式。