SolvedPrivate

vb.Net parse xml with linq query

Posted on 2014-03-19
4
35 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Had a typo in my version
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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.
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

771 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

12 Experts available now in Live!

Get 1:1 Help Now