【发布时间】:2016-06-02 13:15:26
【问题描述】:
我有这段代码用于将值插入到 oracle 数据库中,我得到“缺少逗号”异常,我看不到它来自哪里。
"insert into comandadvd values('" + txt_idComanda.Text + "','" +
txtFormat.Text + "','" + "', to_date('" + txtData.Text + "','DDMMYYY')'" + txtIdTipPlata.Text + "','" + txtPret.Text + "')";
这里还有它的 Oracle 代码:
INSERT INTO ComandaDVD (Id_Comanda,Id_Format,Data_Comanda,Id_TipPlata,Pret)
VALUES ('1','1','12-11-2011','1','200');
提前致谢!
【问题讨论】:
-
您给出的命令是值示例还是实际命令?如果
txtFormat.Text曾经包含O'Leary(或者实际上是Robert'); DROP TABLE ComandaDvd; --),这将非常失败——请阅读 SQL 注入和参数化命令。 -
insert语句在数据库中单独工作,在c#代码中失败?
-
@JeroenMostert
Robert'); DROP TABLE ComandaDvd; --将失败,因为 Oracle(与其他一些 RDBMS 不同)不允许在同一命令中使用多个语句。 -
@MT0:公平点,对于这个特定的命令——当然,SQL 注入对 Oracle 来说也是一个真正的风险。
-
@JeroenMostert: Little Bobby Tables :-)