read xml file into datagridview

  • Thread starter Thread starter dianas28
  • Start date Start date
D

dianas28

Guest
Good evening I am a new to programming, I have a university project that has started from 0 seeing some examples from my professor, the problem is that it does not teach us with xml, I leave part of my code, I dont not know how to load the datagridview with this information and how to save the file. If you can tell me that I can improve my code, I would aprecciate it, or that bookstores would save me work please. I am dropping it in the part of the arregloCliente(0) throws me an error that is null.




With columna
'Cedula Juridica
.DataType = System.Type.GetType("System.String")
.AllowDBNull = False
.Caption = "Cédula jurídica"
.ColumnName = "CedulaJuridica"
_tablaClientes.Columns.Add(columna)

'Razon Social
columna = New DataColumn
.DataType = System.Type.GetType("System.Int32")
.AllowDBNull = False
.Caption = "Razón social"
.ColumnName = "RazonSocial"
_tablaClientes.Columns.Add(columna)

'Direccion
columna = New DataColumn
.DataType = System.Type.GetType("System.String")
.AllowDBNull = False
.Caption = "Dirrecion"
.ColumnName = "Direccion"
_tablaClientes.Columns.Add(columna)

'Provincia
columna = New DataColumn
.DataType = System.Type.GetType("System.String")
.AllowDBNull = False
.Caption = "Provincia"
.ColumnName = "Provincia"
_tablaClientes.Columns.Add(columna)

'Canton
columna = New DataColumn
.DataType = System.Type.GetType("System.String")
.AllowDBNull = False
.Caption = "Canton"
.ColumnName = "Canton"
_tablaClientes.Columns.Add(columna)

'Telefono
columna = New DataColumn
.DataType = System.Type.GetType("System.String")
.AllowDBNull = False
.Caption = "Telefono"
.ColumnName = "Telefono"
_tablaClientes.Columns.Add(columna)


End With

Try
Dim objetoLecturaXML As New ClaseLecturaXML

Dim arregloCliente As String()

Dim fila As DataRow

objetoLecturaXML.nombreArchivoP = "rutadelarchivo"
objetoLecturaXML.abrirArchivo()


While Not objetoLecturaXML._archivoXML.EOF


fila = _tablaClientes.NewRow

fila("CedulaJuridica") = arregloCliente(0)
fila("RazonSocial") = arregloCliente(1)
fila("Direccion") = arregloCliente(2)
fila("Provincia") = arregloCliente(3)
fila("Canton") = arregloCliente(4)
fila("Telefono") = arregloCliente(5)

_tablaClientes.Rows.Add(fila)
_tablaClientes.AcceptChanges()

End While

objetoLecturaXML.cerrarArchivo()
Catch ex As Exception

End Try

Continue reading...
 
Back
Top