1 Replies - 542 Views - Last Post: 27 April 2011 - 04:26 PM Rate Topic: -----

#1 zukeru  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 132
  • Joined: 25-December 09

XML Data Set Help Writing To Selected Element PLZ Help

Posted 26 April 2011 - 01:11 PM

Public Class Form1  

 Dim ds As New DataSet  
 Dim xd As XDocument  
 Dim Qual1, Qual2 As String 

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load  

       ds.ReadXml("C:\Users\<me>\test.xml")  
       cb.DataSource = ds.Tables(0)  
       cb.DisplayMember = "Name" 
       xd = Xdocument.Load("C:\Users\<me>\test.xml")  
       dgv.DataSource = ds.Tables(0)  

    End Sub 

   Private Sub cb_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cb.SelectedIndexChanged  

      Try 

         Dim s = From x In xd...<Employee> Select x Where x.<Name>.Value = cb.Text  

         Qual1 = s.<Qual1>.Value  
         Qual2 = s.<Qual2>.Value  
         Catch ex As Exception  
         End Try 
         MessageBox.Show(Qual1 & " " & Qual2)  
   End Sub 

Private Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click

'How do i make it so when I click the button it saves to the selected element that is selected in cb

end sub




Ok my question is my code for populating employee information based on the name selected in the combobox cb works, However I need to be able to write QUAL1 and QUAL2 to the empoyees who anme is in the combo box can anyone help please.

Is This A Good Question/Topic? 0
  • +

Replies To: XML Data Set Help Writing To Selected Element PLZ Help

#2 deery5000  Icon User is offline

  • D.I.C Addict

Reputation: 73
  • View blog
  • Posts: 922
  • Joined: 09-May 09

Re: XML Data Set Help Writing To Selected Element PLZ Help

Posted 27 April 2011 - 04:26 PM

ah look at your query

try using the LINQ to XML methods. You can get a specific node or element based on your query.

 'New document
        Dim doc As XDocument

        'load file into document
        doc = Xdocument.Load(filepath)


        'Query 
        Dim data = From p In doc.Descendants("Employee  OR PARENT NODE")
                          Where p.Attribute("Name") = CB.TEXT


                        



This allows you to get the correct position within the xml file

just write the vale to this position

Kevin

This post has been edited by deery5000: 27 April 2011 - 04:30 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1