Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
SolvedPrivate

vb.Net parse xml with linq query

Posted on 2014-03-19
4
Medium Priority
?
42 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 64

Accepted Solution

by:
Fernando Soto earned 2000 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 64

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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
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…
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 this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

597 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