Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 我无法使用c更新oracle数据库#_C#_Oracle_Ora 00933 - Fatal编程技术网

C# 我无法使用c更新oracle数据库#

C# 我无法使用c更新oracle数据库#,c#,oracle,ora-00933,C#,Oracle,Ora 00933,我正试图从c#更新我的oracle数据库,但出现了此错误 ORA-00933:SQL命令未正确结束 我不知道该怎么办 String sqlCommand = "UPDATE CLIENTI_CD "; sqlCommand += "set nume_client=" + txtNumeC.Text+ "'"; sqlCommand += ",localit_client="+txtLocalitateC.Text+ "'"; sqlCommand +=",data_n to_date('"+tx

我正试图从c#更新我的oracle数据库,但出现了此错误

ORA-00933:SQL命令未正确结束

我不知道该怎么办

String sqlCommand = "UPDATE CLIENTI_CD ";
sqlCommand += "set nume_client=" + txtNumeC.Text+ "'";
sqlCommand += ",localit_client="+txtLocalitateC.Text+ "'";
sqlCommand +=",data_n to_date('"+txtDataN.Text+"','DDMMYYYY')";
sqlCommand += "where cod_client=" + label1.Text;

异常的直接原因是:

省略了
“'”
s:

省略
“=”

但是,最好的方法是使用参数化查询:

当您不能/不想放置参数化查询时,请至少使用格式化查询


@Catalin Duceac:那么您必须调试:在执行之前,
sqlCommand
字符串是什么?现在我得到了“ORA-01756:引用字符串未正确终止”@Catalin Duceac:我明白了。查看我的编辑,您还有另一个语法错误在调试sql命令时,在对数据库执行查询之前,将查询视为完整字符串是很有帮助的。@DmitryBychenko非常感谢:)请尝试在第4行的paren之后或第5行的“where”之前添加空格。另外,我不知道您的数据来自哪里,但如果您只是直接从文本框输入数据,它似乎对SQL注入开放。
  sqlCommand += "set nume_client='" + txtNumeC.Text + "'";
  sqlCommand += ",localit_client='" + txtLocalitateC.Text + "'";
  sqlCommand +=",data_n = to_date('" + txtDataN.Text+"','DDMMYYYY')"; // please, notice "="
  String sqlCommand = 
    @"update CLIENTI_CD
         set nume_client = :prm_nume_client,
             localit_client = :prm_localit_client,
             data_n = to_date(:prm_date, 'DDMMYYYY')
       where cod_client = :prm_cod_client";
  String sqlCommand = String.Format(
     @"update CLIENTI_CD
          set nume_client = '{0}',
              localit_client = '{1}',
              data_n = to_date('{2}', 'DDMMYYYY')
        where cod_client = {3}",
    txtNumeC.Text, 
    txtLocalitateC.Text, 
    txtDataN.Text, 
    label1.Text);