Q: query of dataadapter

G

Guest

Hello,
I have a SqlDataAdapter component in my design. Is there a way to send a
parameter to the query of SqlDataAdapter, I need go get adapter use a where
clause and extract data. Is it possible?
Thanks,
Jim.
 
B

Brock Allen

Yes. You can access the SqlCommand that's used to do the select via SqlDataAdapter.SelectCommand,
and thus the SqlDataAdapter.SelectCommand.Parameters collection.
 
B

Brock Allen

SqlDataAdapter da = new SqlDataAdapter("select * from authors where au_id
= @id", connString);
da.SelectCommand.Paramaters.Add("@id", "222-33-4444");
DataSet ds = new DataSet();
da.Fill(ds, "MyTable");
 
G

Guest

Thanks Brock,
My dataadapter, sqlconnection and dataset are already in my application as
components, so I am not defining a new sqladapter in the code, can still
change the query and refresh dataset?
Thanks,
Jim.
 
B

Brock Allen

Ah, you've just encountered some of the problems with Drag & Drop ;)

I never use the visual-goo for my DB work. As you can see, it's just as quick
to write those 4 lines of code than it is use whirl the mouse around the
screen... ((oops, I'm starting to sound pedagogical))

Anyway, I don't see why you can't change the code that's been gen'd for you.
At the end of the day, it's just code. But you will have to make sure before
you use the DB goo that you've added in the parameter and its value.

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,044
Latest member
RonaldNen

Latest Threads

Top