XML:
< companies >
< company name = " EMPRESA1 " bd =" BD_ EMPRESA1 "/>
< company name = " EMPRESA2 " bd = " BD_ EMPRESA2 "/>
< company name = " EMPRESA3 " bd = " BD_ EMPRESA3 " />
< company name = " EMPRESA4 " bd = " BD_ EMPRESA4 "/>
companies >
VB.net Code :
Dim _dsdetalle As DataSet 'I have decided to fill the xml data in a data set in the first instance as this me serve to link or fill in the data after a certain combo that eleji to display the information contained in the xml
Private Sub FRM_Load ( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase .Load
Dim Xml As XmlDocument
Dim NodeList As XmlNodeList
Dim Node As XmlNode
Dim _DS As New DataSet
LlenarDS()
Try
Xml = New XmlDocument ()
XML.load (Application.StartupPath & "\\ Inicio.xml " ) 'eye this is the address of the folder where you run the program (software, application, system, etc) because that is where prinicipal I have kept Inicio.xml
NodeList = Xml.SelectNodes( "/empresas/empresa" )
For Each Node In NodeList
Dim rw As DataRow = _dsdetalle.Tables (0). NewRow
rw ( "razon_social" ) = Node.Attributes . getNamedItem ( " name " ) . Value
rw ( "bd" ) = Node.Attributes . GetNamedItem ( "bd" ). Value
_dsdetalle.Tables (0). Rows.Add (rw)
Next
CboEmpresa.DisplayMember = "razon_social"
CboEmpresa.ValueMember = "bd"
CboEmpresa.DataSource _dsdetalle.Tables = (0)
Catch ex As Exception
MsgBox(ex.GetType.ToString & vbNewLine & ex.Message.ToString)
Finally
Console.Read()
End Try
End Sub
'We shape our dataset in a separate thread that links your content to the combo
Private Sub LlenarDS ()
_dsdetalle = New DataSet
_dsdetalle.Tables.Add(0)
With _dsdetalle.Tables(0).Columns
.Add( "razon_social" , System.Type.GetType( "System.String" ))
.Add( "Bd" , System.Type.GetType ( "System.String" ))
End With
End Sub
0 comments:
Post a Comment