SolvedPrivate

vb.Net parse xml with linq query

Posted on 2014-03-19
4
39 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

726 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