Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


How to add Where clause to TabelAdapter

Posted on 2010-09-10
Medium Priority
Last Modified: 2012-05-10

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

Question by:Abdurahman Almatrodi
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2

Accepted Solution

icemokka earned 2000 total points
ID: 33644876
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);

Author Comment

by:Abdurahman Almatrodi
ID: 33644924
Where to add this code?
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33645050
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...

Expert Comment

ID: 33645084
Take a quick look @ this :
It explains extention methods, very handy if you want to reuse your code

Author Comment

by:Abdurahman Almatrodi
ID: 33651567
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

660 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question