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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

filter ADO.net dataset 1

Status
Not open for further replies.

oankaar

Programmer
Mar 19, 2002
3
GB
Hi all

Simple question - I need to know how to filter the data in a dataset. For example in VB6 I would have retrieved the data in a recordset and then filtered using

rs.filter = " surname like '" & txtsurname.txt & "%'"

and then updated the bound grid using

flxCustomers.refresh()

In VB.net I've created a dataset and attempted the following without success

Private Sub txtName_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtName.TextChanged
dsCustomers.Tables("CustomerDetails").Select(" surname like '" & txtName.Text & "%'")
dgCustomers.Refresh()
End Sub

I'm not sure if this is the correct method - but it's the only information that I've managed to locate in MSDN. What I'm trying to do is move my vb6 app into .net - and as an experient changing all ADO references to ADO.net. In my current VB6 app I had set up a grid that could be filtered as the user typed into the textbox by firing the textchanged method.

If this does not make sense - let me know and I'll try to explain it better. Any help would be appreciated.

OM
 
Hi,

Use a dataview to filter your data:

Dim dtMaster as DataTable = dsCustomers.Tables(0)
Dim dv as DataView = New DataView(dt)

dv.Filter = "surname like '" & txtName.Text & "%'"

You will have to bind your data grid to the dataview for this to work.

DataView also has a Sort property (very useful).

Cheers,
Phirst.
 
Thanks phirst

that's worked great.

Cheers,

OM
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top