HQuintas Posted March 27, 2012 at 10:17 PM Report #446028 Posted March 27, 2012 at 10:17 PM Como guardar o conteúdo de um datagridview em um ficheiro XML? Já tentei usar um dataset e writexml, mas não estou conseguindo
Caça Posted March 27, 2012 at 10:18 PM Report #446029 Posted March 27, 2012 at 10:18 PM Está a dar erro? Pedro Martins Não respondo a duvidas por PM
HQuintas Posted March 27, 2012 at 10:55 PM Author Report #446038 Posted March 27, 2012 at 10:55 PM Não... Eu não preenchi o datagridview por um dataset, quero é popular o dataset com os dados que estão no datagridview. Tenho percorrer todos as linhas e colunas da grelha e joga-los num datatable?
Caça Posted March 27, 2012 at 10:57 PM Report #446039 Posted March 27, 2012 at 10:57 PM Se quiseres utilizar esse método, sim. Pedro Martins Não respondo a duvidas por PM
HQuintas Posted March 28, 2012 at 07:19 AM Author Report #446057 Posted March 28, 2012 at 07:19 AM Bom dia E se eu não quiser utilizar esse método... 😁 qual a alternativa?
Caça Posted March 28, 2012 at 08:39 AM Report #446061 Posted March 28, 2012 at 08:39 AM Exportar para um Template ou para um ficheiro criado de raiz por ti, utilizando as classes do namespace XML. Para ser mais fácil e rápido podes utilizar XML Literals, vê aqui vários exemplos http://www.jorgepaulino.com/search/label/XML%20Literals Pedro Martins Não respondo a duvidas por PM
HQuintas Posted March 28, 2012 at 05:01 PM Author Report #446174 Posted March 28, 2012 at 05:01 PM 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now