异常的直接原因是:
省略"'"
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);