471,317 Members | 1,417 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,317 software developers and data experts.

How Do I change the where clause of the TableAdapter

Hi,

in the old days, pre .Net 2.0 I could just modify the SQLCommand of the
SQlDataAdapter to reflect a different where clause and then issue a .Fill(),
and Whamo!!! everything worked.. How am I to accomplish the same task using
..NET 2.0 and the NEW "TableAdapter", I can't see myself creating 100's of
Queries using the wizard, is there anyway for me to just change the sql
Where clause at runtime? I have the TableAdapter bound to a DataGrid, and
am aware that there is a filter property, but I don't think setting this
filter property forces a reread from the database, and my my database
contains 100,000's of records.

any help would be very much appreciated..

thanks,
Feb 18 '06 #1
2 10202
hi,

"Rob Dob" <ro************@yahoo.com> wrote in message
news:OX*************@TK2MSFTNGP15.phx.gbl...
Hi,

in the old days, pre .Net 2.0 I could just modify the SQLCommand of the
SQlDataAdapter to reflect a different where clause and then issue a
.Fill(), and Whamo!!! everything worked.. How am I to accomplish the same
task using .NET 2.0 and the NEW "TableAdapter", I can't see myself
creating 100's of Queries using the wizard, is there anyway for me to
just change the sql Where clause at runtime? I have the TableAdapter
bound to a DataGrid, and am aware that there is a filter property, but I
don't think setting this filter property forces a reread from the
database, and my my database contains 100,000's of records.

Since TableAdapters are partial classes you could extend them by adding
another partial class, eg:

SomeDataSet.cs
------------------

using System.Data.SqlClient;

namespace SomeWindowsApplication
{
namespace SomeDataSetTableAdapters
{
partial class SomeTableAdapter
{
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);
}
}
}
}

(You offcourse have to replace "Some" with the actual names you have and if
you prefer you can easily make it a "FillByWhere" instead.)

HTH,
Greetings

any help would be very much appreciated..

thanks,

Feb 19 '06 #2
Hi,

Thanks, that worked like a Champ!!!
Mar 14 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by dmkeith2 | last post: by
5 posts views Thread by Programatix | last post: by
6 posts views Thread by Altman | last post: by
2 posts views Thread by paolol | last post: by
reply views Thread by Yin99 | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.