How to add Where clause to TabelAdapter


I have a tableadapter already created by the wizard in dataset. I have to add a 'Where xxx In (y1, y2...etc)'. I tried many way like adding a string parameters, but did not work.

How to solve this?, so I can write something like:
myTableAdapter.Fill(dsMainFormReport.tbTheTable, strWhereClause);

Abdurahman AlmatrodiBusiness DevelopmentAsked:
Who is Participating?
You could extend the TableAdaptor object with this proc

public int FillBySelect(SomeDataSet.SomeDataTable Table, string
this.Adapter.SelectCommand = new SqlCommand(Select,
if (this.ClearBeforeFill)

return this.Adapter.Fill(Table);
Abdurahman AlmatrodiBusiness DevelopmentAuthor Commented:
Where to add this code?
John (Yiannis) ToutountzoglouInstructor Multiengine PilotCommented:
Open your desired dataset designer .At the bottom where the fill is shown...Right Click ..add new query, then you will see a selct statement..add a where clause Like this....:
Where Lastname=@Lastname (for example)..Contunue with the wizard..and click finish.
then in a form Load or wherever you want call the table adapter as you said initially with the desired parameter...
Take a quick look @ this :
It explains extention methods, very handy if you want to reuse your code
Abdurahman AlmatrodiBusiness DevelopmentAuthor Commented:
Dear All I am not that guru. Till now I did not get it very well. my mind got crazy about this subject. I did not even try to open the wizard's code before. If I want to add such as "Where xx = @yy" it will be easy, But to use "In (y1, y2...etc)", I couldn't. btw, I hear about LINQ, but I did not use it before. Regards
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.