I have this code for inserting values into a oracle database, and I get "Missing comma" Exception, and I can't see from where it comes.
"insert into comandadvd values('" + txt_idComanda.Text + "','" +
txtFormat.Text + "','" + "', to_date('" + txtData.Text + "','DDMMYYY')'" + txtIdTipPlata.Text + "','" + txtPret.Text + "')";
Alse here it is the Oracle code for it:
INSERT INTO ComandaDVD (Id_Comanda,Id_Format,Data_Comanda,Id_TipPlata,Pret)
VALUES ('1','1','12-11-2011','1','200');
Thanks in advance!
"insert into comandadvd values('" + txt_idComanda.Text + "','" + txtFormat.Text + "','" + "' to_date('" + txtData.Text + "','DDMMYYY')'" + "','" + txtIdTipPlata.Text + "','" + txtPret.Text + "')";
to_date
should not be inside quotes. DD-MM-YYYY
in example. Try this as I havn't tested it and let me know if you get error.
"insert into comandadvd values('" + txt_idComanda.Text + "','" + txtFormat.Text + "','" + "to_date('"
+ txtData.Text + "','DD-MM-YYY')" + txtIdTipPlata.Text + "','" + txtPret.Text + "')";
The immediate cause of the error is in the
"','" + "', to_date('"
fragmanent. The best solution is using parametrized query:
@"insert into comandadvd (
Id_Comanda,
Id_Format,
Data_Comanda,
Id_TipPlata,
Pret)
values (
:prm_Id_Comanda,
:prm_Id_Format,
:prm_Data_Comanda,
:prm_Id_TipPlata,
:prm_Pret)";
In case that for whatever reason you can't use parametrized query, use formatted one:
String.Format(
@"insert into comandadvd (
Id_Comanda,
Id_Format,
Data_Comanda,
Id_TipPlata,
Pret)
values (
{0},
{1},
to_date('{2}', 'DDMMYYY'),
{3},
{4})",
txt_idComanda.Text,
txtFormat.Text,
txtData.Text,
txtIdTipPlata.Text,
txtPret.Text);
The guiding principle is Make your SQL readable
You added extra comma before to_date(
in your query. The corrected code as below:
"INSERT INTO ComandaDVD (Id_Comanda,Id_Format,Data_Comanda,Id_TipPlata,Pret) VALUES (" +
"'" + txt_idComanda.Text + "', " +
"'" + txtFormat.Text + "', " +
"to_date('" + txtData.Text + "', 'DDMMYYY'), " +
"'" + txtIdTipPlata.Text + "', " +
"'" + txtPret.Text + "')";
There appear to be multiple problems:
SELECT
have different capitalization, and there's a field list in the posted SELECT
which the code does not generate; therefore, the SELECT
text you posted was obviously not generated by this code. If you had actually run the code and generated the INSERT statement you'd have found that it doesn't work as you think it does, and you could have fixed it yourself. to_date
. txtIdTipPlata.Text
. INSERT
statements should ALWAYS include a list of the names of the fields to be inserted. Best of luck.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.