c# - Error while using parameters with OdbcDataAdapter -


its bit kind of strange, facing problem not expected behavior.

consider following function:

 public static system.data.dataset getdataset(string cmdstr, system.collections.hashtable parameters)     {         odbcdataadapter adap = new odbcdataadapter(cmdstr, getconnection());                  foreach (object obj in parameters.keys)         {                             adap.selectcommand.parameters.addwithvalue(obj.tostring(), parameters[obj]);         }         system.data.dataset ds = new system.data.dataset();         adap.fill(ds);         return ds;     } 

i use function execute sql command have parameters. eg, consider code:

string qrystr = "exec  bitss_savepaymentdata " +                                 "@cdate=@cdate," +                                 "@payid=@payid," +                                 "@amount=@amount";                 system.collections.hashtable ht = new system.collections.hashtable();                 ht.add("@cdate", datetime.now.date);                 ht.add("@amount", 100);                 ht.add("@payid", 101);                 dataset ds=getdataset(qrystr, ht); 

the problem: above code throws exception "must declare scalar variable @cdate". while same code works if use sqldataadapter instead of odbcdataadapter.

any ideas missing here?

i've tried this:

string connectionstring = "dsn=mysql;uid=sa;database=userdb;"; string qrystr = "insert 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 scalar variable @code" con.close; 

i unable figure out reason exception coming in above code.

i've found solution given in this link.

the odbc interface not recognise use of @named variables, ? taken position. can use ?param1, ?param 2 readability, position used.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -