Solved

Help with filtering data from DataTable

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

Containers & Docker to Create a Powerful Team

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

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…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

636 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