title: Use the value an XML element as a variable for a procedure
body: <p>I am new to working with XML in VB and I trying use the value of an Element DBName to find the the active SQL database name to connect to.  I have looked over a lot of code but it has just made more confused. Any help would be great!</p>
  
  <p>Below is the code for the sub I am trying to use the variable in.  I am trying to get the DBName from an xml document. The structure of the xml is as follows</p>
  
  <pre><code>&lt;db&gt;
  &lt;User&gt;DBUser2&lt;/User&gt;
  &lt;Password&gt;&lt;![CDATA[xka2bOHaQZWesxHLFHlWaVw7JscbNFCobXbqYWc5rwppoNkAn3K1uqriSCHdEzyY/FNDdbgRJTzDEIM8Jc5PYTBzfMUC5UIDtr16a64Xj7MRGI4/AvRcys/fIQDZQ947GesAc1rF/kbZu8AaZDVTjwObbNPT2L/h+IA6WjM9lqv6BOCi4dUeKxx5AneCBy2TJdifxEPdAIOT9lqTm5/aHFD0JgqSn0OTtWbLuYX9KX9uvA8L8zEH51yEmGl258aRVfpGfyxph/cpdnW1miRk4Q==]]&gt;&lt;/Password&gt;
  &lt;Server&gt;N127.0.0.1\CESSQL&lt;/Server&gt;
  &lt;ServerDatabase&gt;Marino&lt;/ServerDatabase&gt;
  &lt;BackupServer&gt;&lt;/BackupServer&gt;
  &lt;BackupDatabase&gt;&lt;/BackupDatabase&gt;
  &lt;MasterPassword&gt;&lt;![CDATA[EFmUxlkmQfIx4w18oQZ1dtCxAIXIyBZPCelL8csYX3E5NuHBZNI42UXNhFxmu87Ksj5CbQpC1WNTj4jnLaaq7nX6Oa4z3M7glLAeRaXWGAd3VqWfADRQAW3RCKKSJRMK3jwRWHJjY1Vp2hgn9CuMACvYHZUrUyK6nJ9HMiwaXcUJKtm4vl0toQNpwIuGvT2cfMJgvpjXJhTBfxKE75ZWeAldXhX5h/c6LYMQ6DE79uuhdbisfmIrXTskKTcceiRjWU2jTFumpjhM1tUqEoBFLw==]]&gt;&lt;/MasterPassword&gt;
  </code></pre>
  
  <p></p>
  
  <pre><code>Imports System.Data
  Imports System.IO
  Imports System.Xml
  Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  
  Dim m_xmld As XmlDocument
          Dim m_nodelist As XmlNodeList
          Dim m_node As XmlNode
          m_xmld = New XmlDocument()
          m_xmld.Load("C:\FPOS5\Data\dbinfo.xml")
          m_nodelist = m_xmld.SelectNodes("/DB/ServerDatabase")
          For Each m_node In m_nodelist
          Dim ServerDatabaseValue =    m_node.Attributes.GetNamedItem("ServerDatabase").Value
          Console.Write(ServerDatabaseValue)
          Next
  
      Dim con As New SqlClient.SqlConnection("server=127.0.0.1\CESSQL;database=" &amp; DBName &amp; ";User ID=;Password=")
      Dim cmd As New SqlClient.SqlCommand
      Dim DriverNumber2 As Integer
      Dim CheckNumber2 As Integer
  
      DriverNumber2 = TextBox1.Text
      CheckNumber2 = TextBox2.Text
  
      Try
          con.Open()
      Catch ex As Exception
          MsgBox("Can not open connection ! ")
      End Try
      cmd = New SqlClient.SqlCommand("Update Sale Set DriverID =" &amp; DriverNumber2 &amp; "where CheckNumber =" &amp; CheckNumber2 &amp; "")
  
  
      cmd.Connection = con
      cmd.ExecuteNonQuery()
      con.Close()
  
      MsgBox("Done")
  End Sub
  </code></pre>