?
Solved

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

Posted on 2007-03-26
4
Medium Priority
?
336 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Command Line Tips and Tricks

The command line is a powerful tool at the disposal of every Linux user. Although Linux distros come with beautiful user interfaces, it's worthwhile to learn the command line because it allows you to do a number of things that you otherwise cannot do from the GUI.  

Question has a verified solution.

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

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

752 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