Parameters in Select statement

cpopham

Well-known member
Joined
Feb 18, 2004
Messages
273
I have an access backend and I have been working with parameters for a while with the Insert, Update, Delete, and Append commands. The ones where you use an executenonquery. Now, I want to use a statement similar to this:

Code:
SELECT * FROM myTable WHERE user = @myUser;"

Now I can do this with using a variable with my dataadapter and have no problems filling my dataset, but the oledbdataadapter will not accept parameters.

So my question is, how can I use this parameterized query and fill a dataset?

Thanks, Chester
 
Just feed a OleDbCommand instance into the OleDbDataAdapter instance:
Code:
OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=mydb.mdb");
conn.Open();

OleDbCommand cmd = new OleDbCommand("SELECT * FROM [MyTable] WHERE [MyID]=@MyID", conn);
cmd.Parameters.Add("MyID", 101);

OleDbDataAdapter a = new OleDbDataAdapter(cmd);

DataSet ds = new DataSet();
a.Fill(ds);

conn.Close();
 
Back
Top