Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

(?,?...?) or (@field1,@field2...@fieldn) in parmeterized queries?

Is this bad coding?

I have a query

INSERT INTO sometable (field1,field2...fieldn) VALUES (?,?,.....?)

Then

cmd.Parameters.Add("TOFnr", OdbcType.Int, 10).Value = orderId;
cmd.Parameters.Add("LineNr", OdbcType.Int, 10).Value = maxLineNr;
cmd.Parameters.Add("Date", OdbcType.VarChar, 8).Value = rowHeader["Date"];

The code works, except there was an if-conditional around an Add, causing the data after that line to get into the wrong variable.

The placeholders ("TOFnr" etc.) is only used for the programmers reference, not used by the sql or c# itself, right?

Isn't it less error-prone to used named parameters in the query?

INSERT INTO sometable (field1,field2...fieldn) VALUES (@TOFnr,@LineNr,.....@fieldn)

It is c# connecting to borland paradox over odbc.

like image 756
Leif Neland Avatar asked Dec 04 '25 10:12

Leif Neland


1 Answers

Isn't it less error-prone to used named parameters in the query?

Yes, it is. Unfortunately the ADO.NET ODBC driver doesn't allow named SQL parameters to be passed along in the SQL statement, so unfortunately for you, it is not possible using the ODBC driver.

I am not an expert on Paradox, but there might be a driver specifically for Paradox which does allow named parameters. You might have more luck there.

like image 129
Patrick Hofman Avatar answered Dec 07 '25 00:12

Patrick Hofman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!