SolvedPrivate

vb.Net parse xml with linq query

Posted on 2014-03-19
4
40 Views
Last Modified: 2016-02-10
My code below works and populate my (rcbFilter) combo box

However....
I need two (2) fields for the value and the text
Region and RegionID to populate my query.ToList when done.

Right now theres only Region

    Private Sub ordersRegionDLL()
        Try
            allDataSet = Session("allDataSet")

            '       Where Region IsNot Nothing _
            Dim Query = _
            (From Region In allDataSet.Tables(0) _
             Where Region.Field(Of String)("Region") <> "" _
                    Select Region.Field(Of String)("Region") _
             ).Distinct().OrderBy(Function(item) item).ToList

            rcbFilter.DataSource = Query.ToList
            rcbFilter.DataBind()
            rcbFilter.Items.Insert(0, New RadComboBoxItem("All", "All"))
            rcbFilter.Items.Insert(1, New RadComboBoxItem("Other", "Other"))
            rcbFilter.Height = 120
            rcbFilter.DropDownWidth = 200
        Catch ex As Exception

        End Try
    End Sub

Open in new window

0
Comment
Question by:lrbrister
[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 63

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 39940286
Hi lrbrister;

Try this modified query.
Dim Query = _
           (From Region In allDataSet.Tables(0) _
            Where Region.Field(Of String)("Region") <> "" _
            Select Region = Region.Field(Of String)("Region"), _
                   RegionID = Region.Field(Of String)("RegionID") _
           ).Distinct().OrderBy(Function(item) item.Region).ToList

Open in new window

0
 

Author Comment

by:lrbrister
ID: 39940378
Fernando,
  That errored out with no selection

I would up using this...

'Query xml 
Dim query3 = _
    (From Region In regionDataSet.Tables(0) _
     Select Region)

'load datatable from query
Dim boundTable As DataTable = query3.CopyToDataTable()

Open in new window


And then bound it with this

rcbFilter.DataValueField = "regionID"
rcbFilter.DataTextField = "regionText"
rcbFilter.DataSource = boundTable
rcbFilter.DataBind()

Open in new window

0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 39940417
What was the exception that was thrown when using the query I posted?

Also you are not filtering the result set and not removing duplicates as in the original question.
0
 

Author Closing Comment

by:lrbrister
ID: 39942679
Had a typo in my version
0

Featured Post

Is Your DevOps Pipeline Leaking?

Is your CI/CD pipeline a hodge-podge of randomly connected tools? You’ve likely got a tool to fix one problem & then a different tool to fix another, resulting in a cluster of tools with overlapping functionality. Learn how to optimize your pipeline with Gartner's recommendations

Question has a verified solution.

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

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…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

705 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