Jump to content

Guardar datagridview wm xml


HQuintas
 Share

Recommended Posts

Então fiz assim: (esqueci o dataset e o datatable)

' Cria um novo ficheiro XML com a codificação UTF8
        Dim xmlw As New XmlTextWriter(cam, System.Text.Encoding.UTF8)
        xmlw.Formatting = Formatting.Indented

        xmlw.WriteStartDocument()

        ' Adiciona um comentário geral
        xmlw.WriteComment("Euromilhões")

        ' Criar um elemento geral
        xmlw.WriteStartElement("chave")

        With xmlw
            'Percorre linha a linha
            For Each linha As DataGridViewRow In DGV_Num.Rows

                .WriteStartElement("Numeros")
                If Not linha.IsNewRow Then
                    'Cria elementos
                    .WriteElementString("N1", linha.Cells(0).Value)
                    .WriteElementString("N2", linha.Cells(1).Value)
                    .WriteElementString("N3", linha.Cells(2).Value)
                    .WriteElementString("N4", linha.Cells(3).Value)
                    .WriteElementString("N5", linha.Cells(4).Value)
                    .WriteElementString("E1", linha.Cells(5).Value)
                    .WriteElementString("E2", linha.Cells(6).Value)
                    .WriteEndElement()
                End If
            Next
            xmlw.WriteEndElement()
            xmlw.WriteEndDocument()

            ' Fecha o documento XML
            xmlw.Flush()
            xmlw.Close()
        End With

Obrigado

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.