Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Writing data from dataset to XML file [modified]

Writing data from dataset to XML file [modified]

Scheduled Pinned Locked Moved Visual Basic
xmlhelp
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    Usharva
    wrote on last edited by
    #1

    I can abke to write data from Dataset to XML File but the problem now i am facing is... i am getting the XML file like this - <NewDataSet> - <PatientID> <patientRegId>NH0000412006</patientRegId> <pat_name>SNI dsen dev1</pat_name> <DOB>1980-06-22T00:00:00+05:30</DOB> <gender>Male</gender> <MaritalStatus>Married</MaritalStatus> <Religion>Christian</Religion> <presentAddress /> <city>Chennai</city> <presentPIN>500013</presentPIN> <Nationaity>Indian</Nationaity> <patientRegId1>NH0000412006</patientRegId1> <episodeNo>1</episodeNo> <visitNo>2</visitNo> <consultantId>5</consultantId> </PatientID> </NewDataSet> but i want the same data in this format <NewDataSet> - <PatientID> <patientRegId>NH0000412006</patientRegId> <pat_name>SNI dsen dev1</pat_name> <DOB>1980-06-22T00:00:00+05:30</DOB> <gender>Male</gender> <MaritalStatus>Married</MaritalStatus> <Religion>Christian</Religion> <presentAddress /> <city>Chennai</city> <presentPIN>500013</presentPIN> <Nationaity>Indian</Nationaity> <patientRegId1>NH0000412006</patientRegId1> - <episodeNo No="1"> <visitNo>2</visitNo> <consultantId>5</consultantId> </episodeNo> </PatientID> </NewDataSet> this is my code Dim SqlDataAdapter2 As New SqlDataAdapter(qry, sqlCon) Dim ds As New DataSet SqlDataAdapter2.Fill(ds, "PatientID") ds.WriteXml("E:\\ss.xml") Thanks in Advance

    modified on Thursday, January 03, 2008 2:29:20 AM

    M V 2 Replies Last reply
    0
    • U Usharva

      I can abke to write data from Dataset to XML File but the problem now i am facing is... i am getting the XML file like this - <NewDataSet> - <PatientID> <patientRegId>NH0000412006</patientRegId> <pat_name>SNI dsen dev1</pat_name> <DOB>1980-06-22T00:00:00+05:30</DOB> <gender>Male</gender> <MaritalStatus>Married</MaritalStatus> <Religion>Christian</Religion> <presentAddress /> <city>Chennai</city> <presentPIN>500013</presentPIN> <Nationaity>Indian</Nationaity> <patientRegId1>NH0000412006</patientRegId1> <episodeNo>1</episodeNo> <visitNo>2</visitNo> <consultantId>5</consultantId> </PatientID> </NewDataSet> but i want the same data in this format <NewDataSet> - <PatientID> <patientRegId>NH0000412006</patientRegId> <pat_name>SNI dsen dev1</pat_name> <DOB>1980-06-22T00:00:00+05:30</DOB> <gender>Male</gender> <MaritalStatus>Married</MaritalStatus> <Religion>Christian</Religion> <presentAddress /> <city>Chennai</city> <presentPIN>500013</presentPIN> <Nationaity>Indian</Nationaity> <patientRegId1>NH0000412006</patientRegId1> - <episodeNo No="1"> <visitNo>2</visitNo> <consultantId>5</consultantId> </episodeNo> </PatientID> </NewDataSet> this is my code Dim SqlDataAdapter2 As New SqlDataAdapter(qry, sqlCon) Dim ds As New DataSet SqlDataAdapter2.Fill(ds, "PatientID") ds.WriteXml("E:\\ss.xml") Thanks in Advance

      modified on Thursday, January 03, 2008 2:29:20 AM

      M Offline
      M Offline
      Michael Sync
      wrote on last edited by
      #2

      What are the differences?

      Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net)

      U 1 Reply Last reply
      0
      • M Michael Sync

        What are the differences?

        Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net)

        U Offline
        U Offline
        Usharva
        wrote on last edited by
        #3

        I need to crete child Nodes

        1 Reply Last reply
        0
        • U Usharva

          I can abke to write data from Dataset to XML File but the problem now i am facing is... i am getting the XML file like this - <NewDataSet> - <PatientID> <patientRegId>NH0000412006</patientRegId> <pat_name>SNI dsen dev1</pat_name> <DOB>1980-06-22T00:00:00+05:30</DOB> <gender>Male</gender> <MaritalStatus>Married</MaritalStatus> <Religion>Christian</Religion> <presentAddress /> <city>Chennai</city> <presentPIN>500013</presentPIN> <Nationaity>Indian</Nationaity> <patientRegId1>NH0000412006</patientRegId1> <episodeNo>1</episodeNo> <visitNo>2</visitNo> <consultantId>5</consultantId> </PatientID> </NewDataSet> but i want the same data in this format <NewDataSet> - <PatientID> <patientRegId>NH0000412006</patientRegId> <pat_name>SNI dsen dev1</pat_name> <DOB>1980-06-22T00:00:00+05:30</DOB> <gender>Male</gender> <MaritalStatus>Married</MaritalStatus> <Religion>Christian</Religion> <presentAddress /> <city>Chennai</city> <presentPIN>500013</presentPIN> <Nationaity>Indian</Nationaity> <patientRegId1>NH0000412006</patientRegId1> - <episodeNo No="1"> <visitNo>2</visitNo> <consultantId>5</consultantId> </episodeNo> </PatientID> </NewDataSet> this is my code Dim SqlDataAdapter2 As New SqlDataAdapter(qry, sqlCon) Dim ds As New DataSet SqlDataAdapter2.Fill(ds, "PatientID") ds.WriteXml("E:\\ss.xml") Thanks in Advance

          modified on Thursday, January 03, 2008 2:29:20 AM

          V Offline
          V Offline
          Volker Weichert
          wrote on last edited by
          #4

          I am guessing that you have more than one episode per patient and more than one visit per episode. You can always write your own filter to create the XmlDocument you need by iterating through the rows and adding the appropriate nodes to the XmlDocument. Then you can call the Write() method of the XmlDocument. Volker Weichert

          U 1 Reply Last reply
          0
          • V Volker Weichert

            I am guessing that you have more than one episode per patient and more than one visit per episode. You can always write your own filter to create the XmlDocument you need by iterating through the rows and adding the appropriate nodes to the XmlDocument. Then you can call the Write() method of the XmlDocument. Volker Weichert

            U Offline
            U Offline
            Usharva
            wrote on last edited by
            #5

            Yes you are right... but i dont know how to write node by node using Dataset.. pelase can u help me

            V 1 Reply Last reply
            0
            • U Usharva

              Yes you are right... but i dont know how to write node by node using Dataset.. pelase can u help me

              V Offline
              V Offline
              Volker Weichert
              wrote on last edited by
              #6

              Try something like this:

              Dim doc As XmlDocument = New XmlDocument()
              Dim tableName As String = "myTable"
              Dim node, attrib As XmlNode
              Dim parentNode As XmlNode = doc.DocumentElement
              For Each row As DataRow In ds.Tables(tableName).rows
              node = doc.CreateNode(XmlNodeType.Element, "myElement", myNameSpaceURI)
              attrib = doc.CreateAttribute("myAttribute")
              attrib.Value = row("myAttributeColumn").ToString()
              node.Attributes.Append(attrib)
              parentNode.AppendChild(node)
              Next

              You just need to adjust this to fit your own table. Volker Weichert

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups