[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2007-03-26
4
Medium Priority
?
341 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 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

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

Question has a verified solution.

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

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

867 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