Solved

Help with filtering data from DataTable

Posted on 2014-02-17
4
222 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
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 …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

830 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