Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

____________________________________________

http://www.pophamcafe.com

I am starting a developers section, more tutorials than anything.

Posted
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();

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...