Link to home
Create AccountLog in
Avatar of desiredforsome
desiredforsome

asked on

VB.NET Sort XML file by 2nd Word in Name

Hello All,

I have an XML file where it has a elemtn called "Student Name" It has first name and last name I want it to sort by the last name in the gridview but cannot figure it out. Here is my current query.

Dim xdoc As System.Xml.Linq.XDocument
            xdoc = System.Xml.Linq.XDocument.Load(dbfile)
            Dim studentQuery = From student In xdoc.Descendants("Student") _
                               Order By student.Value
                                                                                            Select New With _
                              { _
                                .Name = student.Element("StudentName").Value, _
                                .StudentID = student.Element("StudentID").Value, _
                                .Val = student.Element("Val").Value, _
                                .Sal = student.Element("Sal").Value, _
                                .Summa = student.Element("Summa").Value, _
                                .Magna = student.Element("Magna").Value, _
                                .Cum = student.Element("Cum").Value _
                                }


            Me.DataGridView1.DataSource = studentQuery.ToList()

Open in new window



here is my current xml
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<NewDataSet>
  <Student>
    <StudentName>Jesus Arevalo</StudentName>
    <StudentID>4801428579</StudentID>
    <Val>NO</Val>
    <Sal>NO</Sal>
    <Summa>NO</Summa>
    <Magna>NO</Magna>
    <Cum>NO</Cum>
  </Student>
  <Student>
    <StudentName>Leonardo Cabrera Perez</StudentName>
    <StudentID>4804020466</StudentID>
    <Val>NO</Val>
    <Sal>NO</Sal>
    <Summa>NO</Summa>
    <Magna>NO</Magna>
    <Cum>NO</Cum>
  </Student>
  <Student>
    <StudentName>Carlos Caceres</StudentName>
    <StudentID>4801701593</StudentID>
    <Val>NO</Val>
    <Sal>NO</Sal>
    <Summa>NO</Summa>
    <Magna>NO</Magna>
    <Cum>NO</Cum>
  </Student>
</NewDataSet>

Open in new window


How do I get it to sort by the last name in the DataGridView? I know i have to find a way for it to read the second word after the first word in order to do that. I am at a loss. Please help
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of desiredforsome
desiredforsome

ASKER

Fixed everything Thank You!