Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Filter Dataset on a form

Status
Not open for further replies.

Ed Andres

IS-IT--Management
Mar 27, 2001
142
US
I am new to C# and have a question regarding filtering of data. I have created a poject with a single form. In the project I added a Data Source with a data set to a single table in my database.

I then dropped the Details of the data set on my form which gave me textboxes for each column and also added a navigation bar to the form. When I run the form the data is as expected and I can add, delete, and edit the records.

My questions is can I filter the data based on a particular column and it contents?

I have read a lot about using Select and have tried to use it to no avail.

This is the code that loads the data, added automatically for me:
private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'dSLogin.Login' table. You can move, or remove it, as needed.
this.loginTableAdapter.Fill(this.dSLogin.Login);

}

I added a button to try to execute some sort of filter and here is the code I have for that - it does not produce an error but also does not filter the data.
private void button1_Click(object sender, EventArgs e)
{
this.dSLogin.Login.Select("TechName = 'E Andres'", "TechName", DataViewRowState.CurrentRows);
}

Any help is appreciated.


Ed
 
I think the Select() method returns an array of DataRow objects (I assume your using a strongly typed dataset). You will need to bind/display that result into your UI.
Code:
 [COLOR=green]// You can add a breakpoint on the line below to
 // debug if there are indeed selected rows.
 [/color]
 [b]DataRow[] rows = [/b]this.dSLogin.Login.Select(...);
 [COLOR=green]// ... then, decide how you will display the returned rows[/color]
 
Phinoppix,
You assumption about typed dataset got me looking more closely and I found exactly what I was looking for. I set a new query on the table in question using a parameterized WHERE statement and then can fill the data based on that query like below:

this.loginTableAdapter.FillbyLogin(this.dSLogin.Login, "E Andres");

Thanks for youe help!


Ed
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top