Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ODBC must declare the scalar variable

Tags:

c#

ado.net

odbc

Consider the code below:

string ConnectionString = "dsn=mysql;uid=sa;DATABASE=userdb;";
string qryStr = "insert into info(code) values(@code);";
OdbcConnection con = new OdbcConnection(ConnectionString);
OdbcCommand cmd = new OdbcCommand(qryStr,con );
cmd.Parameters.Add("@code", System.Data.Odbc.OdbcType.Int).Value = "999";
cmd.Connection.Open();
OdbcDataReader odbcdtr = cmd.ExecuteReader();//exception "must declare the scalar  variable @code"
con.Close;

This code is raising exception "must declare scalar vairable @code". I'll be very grateful if anyone can point out the mistake that is in the code above.

like image 867
Amit Mittal Avatar asked Oct 27 '25 05:10

Amit Mittal


1 Answers

I've finally found the solution as given in this link.

The Odbc interface does not recognise the use of @named variables, only ? which are taken by position. You can use ?Param1, ?Param 2 for readability, but the position is all that is used.

like image 116
Amit Mittal Avatar answered Oct 29 '25 20:10

Amit Mittal