Unanswered: Select Query with parameters from C# to DB2 is not working???
In our application we are accessing db2 with the select query like this."SELECT * FROM MYTABLE WHERE ID =?" with the parameter given.This throws an exception
"Unhandled Exception: System.Data.OleDb.OleDbException: No error information available: DB_E_NOCOMMAND(0x80040E0C)."
If i give the query like "SELECT * FROM MYTABLE WHERE ID =1", IT'S WORKING FINE.
Re: Select Query with parameters from C# to DB2 is not working???
I am not entirely sure if this is the proper solution to your problem, but here goes:
I am assuming that you want to be able to pass a string or an int, which will be later used in your query, so be sure to define it:
string MyInput = MyTextBox.Text; //This will look read from your textbox
You already know how to establish a connection and all of that stuff, however, you need to take a few steps to make SQL use your C# defined field:
"SELECT * FROM MyTable WHERE id = @MyParam"
cmd.Parameters.Add ("@MyParam", SqlDbType.VarChar);
cmd.Parameters["@MyParam"].Value = MyIput;
This has allowed me to be able to query a database, and I am currently playing around with it to see what all it can do. You may want to look for more information regarding parameters - I think that is where you will find your solution.