Solved

Simple ADO.NET search, filter data entry form 1.X

Posted on 2007-03-26
4
326 Views
Last Modified: 2008-09-12
I know this isn't difficult, but I've been looking for a clear example or solution to get this to work for a while and I need some expert advice, or someone to point me to a good example. ADO.NET 1.X only, I am using Visual Studio 2003

I need some guidance on how to properly setup a VB.NET WinForm with Search/Filter functionality.

I have successfully setup a connection to SQL Server and I can navigate through all my records, edit them, update them etc.  I navigate using this sort of statement, where objdsSales is an instance of my dsSales Dataset.

        Me.lblNavLocation.Text = (((Me.BindingContext(objdsSales, "sales").Position + 1).ToString + " of  ") _
                    + Me.BindingContext(objdsSales, "sales").Count.ToString)

Everything works fine except I can't grasp how to filter or search for subsets of my DataSet.  I want to use SQL statements to bring up specific records, or groups of them and have my controls automatically filled in with that data.  For instance, if they want all records starting with an order number of 1, I want to use an SQL statement to get those records, and be able to navigate through that subset and view/update them.

I have tried finding a record in a dataview, sorted by my primary key and then getting that index value and changing my position in the main form.
Me.BindingContext(objdsSales, "sales").Position = FoundIndex

That works except I cant filter by multiple records.  What should I be doing?

Thanks in advance for the help.
0
Comment
Question by:Pat-Kel
  • 2
  • 2
4 Comments
 
LVL 18

Expert Comment

by:vbturbo
Comment Utility
Hi

Filtering a dataset is very simple

_ds.Tables("Employee").DefaultView.RowFilter = "ID = 5"

or return a dataview to bind to e.g. a datagrid(view)
 
Dim dv As DataView = _ds.Tables("Employee").DefaultView
dv.RowFilter = " Firstname LIKE '%" + txtsearch.Text + "%' "
dv.Sort = "Firstname "
ParentGridView.DataSource = dv

vbturbo
0
 

Author Comment

by:Pat-Kel
Comment Utility
Thanks vbturbo.  I can definitely sort and I know how to do that.

My problem, as explained above was getting that filtered data to be navigable through the CurrencyManager.  I have since fixed that problem by binding all my controls to the DataView rather than the DataSet.

I have a new problem now though.  When I call AddNew() on my DataView, it allocates space for a new row, and my row Count will increment from 10 to 11 or whatever, but my form will not refresh and change focus to that new added record for editing.  Also, with my navigation buttons, I can't reposition to the last record (the new one).  For instance, even though position number 11 has been added, I can't navigate past 10.

If anyone has any comments on why this might happen, they would be appreciated.
0
 
LVL 18

Accepted Solution

by:
vbturbo earned 500 total points
Comment Utility
Hi

Then it would be better if you bind your  txt fields to a datatable instead.
That way the currency manager recognises added/ deleted row in the table

http://msdn2.microsoft.com/en-us/library/system.windows.forms.currencymanager.aspx

http://msdn2.microsoft.com/en-us/library/system.windows.forms.currencymanager.addnew.aspx

else you'll need to bring the dataview into edit mode
http://msdn2.microsoft.com/en-us/library/system.data.dataview.aspx

vbturbo
0
 

Author Comment

by:Pat-Kel
Comment Utility
The problem has been resolved and is actually related to the back end data tables having tons of duplicate records and some other peculiarities.

Thanks for the suggestions though, you get the points.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This video discusses moving either the default database or any database to a new volume.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

743 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now