Solved

How to add Where clause to TabelAdapter

Posted on 2010-09-10
5
676 Views
Last Modified: 2012-05-10
Hi

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

Regards
0
Comment
Question by:Almatrodi
  • 2
  • 2
5 Comments
 
LVL 2

Accepted Solution

by:
icemokka earned 500 total points
Comment Utility
You could extend the TableAdaptor object with this proc

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

return this.Adapter.Fill(Table);
}
0
 
LVL 1

Author Comment

by:Almatrodi
Comment Utility
Where to add this code?
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
Comment Utility
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...
0
 
LVL 2

Expert Comment

by:icemokka
Comment Utility
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
0
 
LVL 1

Author Comment

by:Almatrodi
Comment Utility
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
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now