[Webinar] Streamline your web hosting managementRegister Today

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 686
  • Last Modified:

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 Almatrodi
Abdurahman Almatrodi
  • 2
  • 2
1 Solution
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 : http://msdn.microsoft.com/en-us/library/bb383977.aspx
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

Featured Post

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now