Foros del Web » Programación para mayores de 30 ;) » .NET »

Problema actualizando XML.

Estas en el tema de Problema actualizando XML. en el foro de .NET en Foros del Web. Espero me puedan ayudar, Tengo una aplicacion en .Net que administra contactos telefonicos. Al presionar el boton Actualizar, para aplicar los cambios hechos a un ...
  #1 (permalink)  
Antiguo 15/11/2005, 13:46
 
Fecha de Ingreso: octubre-2004
Mensajes: 55
Antigüedad: 19 años, 6 meses
Puntos: 0
Pregunta Problema actualizando XML.

Espero me puedan ayudar,

Tengo una aplicacion en .Net que administra contactos telefonicos. Al presionar el boton Actualizar, para aplicar los cambios hechos a un contacto me aparece el error:

Object reference not set to an instance of an object.

Este es el codigo del evento:

Código:
Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
        'Try
            'Send updates to xml file
        Dim xDoc As XmlDocument = New XmlDocument()
        Dim root, id As XmlNode
        Dim i As Integer
        root = xDoc.DocumentElement

        For i = 0 To root.ChildNodes.Count - 1 'AQUI ME SEÑALA EL ERROR
            id = root.ChildNodes(i).Attributes("CustomerID")
            If (id.InnerText = txtUniqueID.Text) Then
                xDoc.DocumentElement("CustomerID").Value = txtUniqueID.Text
                xDoc.DocumentElement("CompanyName").Value = txtCoName.Text
                xDoc.DocumentElement("ContactName").Value = txtContact.Text
                xDoc.DocumentElement("ContactTitle").Value = txtTitle.Text
                xDoc.DocumentElement("Address1").Value = txtAddress.Text
                xDoc.DocumentElement("Phone1").Value = txtPhone1.Text
                xDoc.DocumentElement("Phone2").Value = txtPhone2.Text
            End If
        Next i
        xDoc.Save(m_connCustomers)

        'Reset and begin again
        LoadDataSet()
        MsgBox("Record has been updated.")
        'Attempt to update the datasource.
        Me.LoadDataSet()
        'Catch eUpdate As System.Exception
        '    'Add your error handling code here.
        '    'Display error message, if any.
        '    System.Windows.Forms.MessageBox.Show(eUpdate.Message)
        'End Try
        Me.dsCust_PositionChanged()

    End Sub
Gracias por su ayuda.
  #2 (permalink)  
Antiguo 15/11/2005, 14:46
Avatar de xknown  
Fecha de Ingreso: diciembre-2004
Ubicación: Cusco - Perú
Mensajes: 2.248
Antigüedad: 19 años, 3 meses
Puntos: 7
Y dónde cargas el documento XML?? porque a simple vista creo que xDoc.DocumentElement es nulo...

Saludos
__________________
Alex Concha
Buayacorp - Programación y Diseño
  #3 (permalink)  
Antiguo 15/11/2005, 15:06
 
Fecha de Ingreso: octubre-2004
Mensajes: 55
Antigüedad: 19 años, 6 meses
Puntos: 0
Ok... me faltó una linea...

Ahora el error me lo marca EL MISMO ERROR en la linea siguiente...

Código:
Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
        'Try
            'Send updates to xml file
        Dim xDoc As XmlDocument = New XmlDocument()
              xDoc.Load("Contactos.xml") '<----- LA LINEA QUE FALTABA
        Dim root, id As XmlNode
        Dim i As Integer
        root = xDoc.DocumentElement

        For i = 0 To root.ChildNodes.Count - 1 
            id = root.ChildNodes(i).Attributes("CustomerID")
           If (id.InnerText = txtUniqueID.Text) Then 'AHORA AQUI ME SEÑALA EL ERROR 
                xDoc.DocumentElement("CustomerID").Value = txtUniqueID.Text
                xDoc.DocumentElement("CompanyName").Value = txtCoName.Text
                xDoc.DocumentElement("ContactName").Value = txtContact.Text
                xDoc.DocumentElement("ContactTitle").Value = txtTitle.Text
                xDoc.DocumentElement("Address1").Value = txtAddress.Text
                xDoc.DocumentElement("Phone1").Value = txtPhone1.Text
                xDoc.DocumentElement("Phone2").Value = txtPhone2.Text
            End If
        Next i
        xDoc.Save(m_connCustomers)

        'Reset and begin again
        LoadDataSet()
        MsgBox("Record has been updated.")
        'Attempt to update the datasource.
        Me.LoadDataSet()
        'Catch eUpdate As System.Exception
        '    'Add your error handling code here.
        '    'Display error message, if any.
        '    System.Windows.Forms.MessageBox.Show(eUpdate.Message)
        'End Try
        Me.dsCust_PositionChanged()

    End Sub
  #4 (permalink)  
Antiguo 15/11/2005, 15:14
Avatar de xknown  
Fecha de Ingreso: diciembre-2004
Ubicación: Cusco - Perú
Mensajes: 2.248
Antigüedad: 19 años, 3 meses
Puntos: 7
Hmm, creo que tienes que ir depurando el código que tienes, no creo que pueda ayudarte más si no dices qué error te dá, no das el ejemplo del archivo XML que tienes, etc, etc. Te sugiero que uses XPath, para ese tipo de cosas...

Saludos
__________________
Alex Concha
Buayacorp - Programación y Diseño
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 21:11.