cpopham Posted April 20, 2005 Posted April 20, 2005 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: 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 Quote ____________________________________________ http://www.pophamcafe.com I am starting a developers section, more tutorials than anything.
Mister E Posted April 20, 2005 Posted April 20, 2005 Just feed a OleDbCommand instance into the OleDbDataAdapter instance: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(); Quote
cpopham Posted April 20, 2005 Author Posted April 20, 2005 Thank you, I will give it a try. Chester Quote ____________________________________________ http://www.pophamcafe.com I am starting a developers section, more tutorials than anything.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.