>>I have created data reader with parameters many times but now I need to create a dataset and I am lost.
>>
>>Here is an example:
>>
>>
>>OleDbConnection oDbConnection = new OleDbConnection
>>(connectionString);
>>
>>string strSqlCommand = "select * MYTABLE where MYFIELD(?)";
>>
>>OleDbDataAdapter objAdapter = new OleDbDataAdapter(strSqlCommand,
>>oDbConnection);
>>
>>DataSet dsMyTable = new DataSet();
>>
>>objAdapter.Fill(dsMyTable, "tblMyTable");
>>
>>
>>
>>Somewhere above I have to specify parameter for field MYFIELD but I don't know how and where.
>>
>>Thank you in advance for any help.
>
>
>I found out that I probably need to add the parameret to the Adapter object, as following:
>
>
>objAdapter.GetFillParameters()[0].Value = nMyValue;
>
>
>But I get an error on this line that index is invalid. So I think I need to find a way to specify that the adapter takes so many paramenters. I can't find how to do it so far.
Dmitry,
I usually use parameters with SPROCS instead of with straight SQL, so I don't know exactly what you need to do, but I think you are specifying your parameter incorrectly in your SQL.
Try changing you SQL to something like this:
"select * MYTABLE where MYFIELD = @MyFieldParm";
and your code to something like this:
objAdapter.GetFillParameters()["@MyFieldParm"].Value = nMyValue;