我正在尝试从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;
答案 0 :(得分:1)
异常的直接原因是:
省略了"'"
s:
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);