Solved

Help with filtering data from DataTable

Posted on 2014-02-17
4
219 Views
Last Modified: 2014-02-18
Hi,

I'm trying the code below to filter data from a DataTable, when I use C1TrueDBGrid1.DataSource = FilteredDT I get the correct number of records but I need to display only two columns, when I tried the code below:

Me.C1TrueDBGrid1.DataSource = FilteredDT.DefaultView.ToTable(True, New String() {"SN", "NAS"})

Only one record is displayed. How do I get the correct number of records along with the columns I want to display?
 


Dim SearchCriteria As String = "LinkAID <> -1 AND CHPT > 103 AND CHPT < 106"
        Dim FilteredDT As DataTable
        Dim DV As New DataView(dtsetLinkBEL.Tables(0), SearchCriteria, Nothing, DataViewRowState.CurrentRows)
        FilteredDT = DV.ToTable
        If FilteredDT.Rows.Count > 0 Then
            ' C1TrueDBGrid1.DataSource = FilteredDT
            Me.C1TrueDBGrid1.DataSource = FilteredDT.DefaultView.ToTable(True, New String() {"SN", "NAS"})
        End If

Thanks,

Victor
0
Comment
Question by:vcharles
  • 2
4 Comments
 
LVL 14

Expert Comment

by:Matti
ID: 39866456
Hi!

Make a query, import this to Access from SQL as query and make VBA code to filter it and you can add there as many fields you like in Access query builder. Then bound this to the application but this would be difficult to redistribute as there are two database bound together and they have hard coded paths. If the original database is Access then it's lot simpler. You can make a system or user data-source on the computer and bound it into a query in access external data-source.
0
 

Author Comment

by:vcharles
ID: 39866562
Hi,

I'm converting data from an XML file to a datatable dtsetLinkBEL.Tables(0).

 fsLinkBEL = New System.IO.FileStream(Application.StartupPath + "\linkSearch.xml", IO.FileMode.Open)
        dtsetLinkBEL.Clear()
        dtsetLinkBEL.ReadXml(fsLinkBEL)
        fsLinkBEL.Close()

V.
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 39867995
Change this

Me.C1TrueDBGrid1.DataSource = FilteredDT.DefaultView.ToTable(True, New String() {"SN", "NAS"})

to

Me.C1TrueDBGrid1.DataSource = FilteredDT.DefaultView.ToTable(False, New String() {"SN", "NAS"})
0
 

Author Closing Comment

by:vcharles
ID: 39868331
Thank You.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
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 …
This video discusses moving either the default database or any database to a new volume.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

747 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

13 Experts available now in Live!

Get 1:1 Help Now