Solved

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

Posted on 2007-03-26
4
327 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
ID: 18806141
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
ID: 18807323
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
ID: 18808726
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
ID: 18808760
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

911 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

19 Experts available now in Live!

Get 1:1 Help Now