SolvedPrivate

vb.Net parse xml with linq query

Posted on 2014-03-19
4
37 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
  • 2
  • 2
4 Comments
 
LVL 62

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 62

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
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…

813 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

18 Experts available now in Live!

Get 1:1 Help Now