tags:

views:

44

answers:

2

I've added a dataset , and a table adapter to my C# project.(The dataset and tableadapter was added via DataSources box) In this query , I get table data , then filter , then I will iterate and fill a listbox.

listBox1.Items.Clear();
ETPDataset.t_USR_UsersDataTable tbl = (new ETPDataset.t_USR_UsersDataTable());
ETPDatasetTableAdapters.t_USR_UsersTableAdapter tblAdap = new TestIntellisenseSql.ETPDatasetTableAdapters.t_USR_UsersTableAdapter();
tblAdap.Connection.ConnectionString = scon.ConnectionString;
tblAdap.Fill(tbl);
ETPDataset.t_USR_UsersRow[] rows2;
rows2 = (ETPDataset.t_USR_UsersRow[])tbl.Select("USR_RECORDID > 60");
foreach (ETPDataset.t_USR_UsersRow drow in rows2)
{
listBox1.Items.Add(drow.USR_UserID);
}

This is my problem

tblAdap.Fill(tbl);

because this line of code will fetch ALL data(problem for big tables) , how can i fix it ? -Thanks

+2  A: 

Create a new method on your adapter to use a where clause to filter the data at the database.

ck
There is no point to fetching all the data from database and filter it at program. Is there any problem you cant filter "USR_RECORDID > 60" at database?
Umair Ahmed
Once you added the filter to the adapter, the Fill() method will take the value as a parameter, ie Fill(USR_ID)
Wez
Edit your dataset in the designer, r-click the data table and choose 'Configure'. In the query insert your parameter (@ID), click Finish.
Wez
I would not want to use stored procedure
@KeyboardMonkey Thanks a lotThis way I do not have to hard code the column names but It help me use intellisense.
A: 

@ck Okay I see , however how will i be able to edit the predicate while app is running , the only part I want to be able to edit is the

USR_RECORDID > "user chosen value"

You don't need to create a new answer to post replies, use the Comment sections instead.
Wez