[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

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…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

656 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