Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to add Where clause to TabelAdapter

Posted on 2010-09-10
5
Medium Priority
?
685 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:Abdurahman Almatrodi
  • 2
  • 2
5 Comments
 
LVL 2

Accepted Solution

by:
icemokka earned 2000 total points
ID: 33644876
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:Abdurahman Almatrodi
ID: 33644924
Where to add this code?
0
 
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...
0
 
LVL 2

Expert Comment

by:icemokka
ID: 33645084
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: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
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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.
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…

824 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