Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to create DataSet from SqlSelect with parameter?
Message
General information
Forum:
ASP.NET
Category:
ADO.NET
Environment versions
Environment:
C# 2.0
Miscellaneous
Thread ID:
01272138
Message ID:
01272222
Views:
18
This message has been marked as the solution to the initial question of the thread.
>>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.

Something like this should work:
OleDbConnection oDbConnection = new OleDbConnection(connectionString);
string strSqlCommand = "SELECT * FROM MyTable WHERE MyField = ?";
OleDbDataAdapter objAdapter = new OleDbDataAdapter(strSqlCommand, oDbConnection);
            objAdapter.SelectCommand.Parameters.Add("MyParameter", OleDbType.VarChar).Value = "SomeValue";
DataSet dsMytable = new DataSet();
objAdapter.Fill(dsMytable, "tblMyTable");
-Paul

RCS Solutions, Inc.
Blog
Twitter
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform