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. Web Development
  3. ASP.NET
  4. XML Upload

XML Upload

Scheduled Pinned Locked Moved ASP.NET
databasexml
8 Posts 4 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.
  • R Offline
    R Offline
    rockyl
    wrote on last edited by
    #1

    Hi, I need to read the contents of a xml file and upload them into a database. Do we have any xml specific class which could be used in this scenario. Thanks in Advance:

    Rakesh

    G N 2 Replies Last reply
    0
    • R rockyl

      Hi, I need to read the contents of a xml file and upload them into a database. Do we have any xml specific class which could be used in this scenario. Thanks in Advance:

      Rakesh

      G Offline
      G Offline
      gauthee
      wrote on last edited by
      #2

      Using XmlDocument you can load your xml file. The namespace would be System.Xml You can use the Xml Path to acces your nodes in your xml file accordingly. To see more examples on xpath refer w3schools.com

      Gautham

      R 1 Reply Last reply
      0
      • G gauthee

        Using XmlDocument you can load your xml file. The namespace would be System.Xml You can use the Xml Path to acces your nodes in your xml file accordingly. To see more examples on xpath refer w3schools.com

        Gautham

        R Offline
        R Offline
        rockyl
        wrote on last edited by
        #3

        Thanks for the response I am already using XMLDocument class. Let me tell you what exactly I am doing: I am reading one set of record of an xml file and opening a SQL connection and inserting the data and then closing the connection. If I have 100 set of records in the XML file then my application opens connection 100 times which I dont see appropriate. I want to do it at one short. Read all the sets from the xml file, open the connection and insert all the records and close it. Do we have any way to do this?

        Rakesh

        B 1 Reply Last reply
        0
        • R rockyl

          Thanks for the response I am already using XMLDocument class. Let me tell you what exactly I am doing: I am reading one set of record of an xml file and opening a SQL connection and inserting the data and then closing the connection. If I have 100 set of records in the XML file then my application opens connection 100 times which I dont see appropriate. I want to do it at one short. Read all the sets from the xml file, open the connection and insert all the records and close it. Do we have any way to do this?

          Rakesh

          B Offline
          B Offline
          badgrs
          wrote on last edited by
          #4

          Why are you opening and closing the connection? Why not open the connection and command object, loop through the records in the XML file building the SQL on the fly each time and runnning the query. Only close the connection once your done.

          R 1 Reply Last reply
          0
          • R rockyl

            Hi, I need to read the contents of a xml file and upload them into a database. Do we have any xml specific class which could be used in this scenario. Thanks in Advance:

            Rakesh

            N Offline
            N Offline
            Nicejith
            wrote on last edited by
            #5

            I think its very easy to use the Dataset method.. ie use the namespace System.Data then code as follows Dataset Ds; ds.ReadXml(xmlfilepath); here if you check the dataset viewer, you can see all the xml contents as tables. from there you can extract data and put it in database.

            R 2 Replies Last reply
            0
            • N Nicejith

              I think its very easy to use the Dataset method.. ie use the namespace System.Data then code as follows Dataset Ds; ds.ReadXml(xmlfilepath); here if you check the dataset viewer, you can see all the xml contents as tables. from there you can extract data and put it in database.

              R Offline
              R Offline
              rockyl
              wrote on last edited by
              #6

              Thank you, I will try it out...

              Rakesh

              1 Reply Last reply
              0
              • B badgrs

                Why are you opening and closing the connection? Why not open the connection and command object, loop through the records in the XML file building the SQL on the fly each time and runnning the query. Only close the connection once your done.

                R Offline
                R Offline
                rockyl
                wrote on last edited by
                #7

                Yah thats really a simple idea. But I see one issue here. Let say that there are 100 sets of employee records in the xml file and the process finished inserting 60 of the records and suddenly the connection is lost, then what must be done. I mean how can we track the record to be inserted next. Thanks:

                Rakesh

                1 Reply Last reply
                0
                • N Nicejith

                  I think its very easy to use the Dataset method.. ie use the namespace System.Data then code as follows Dataset Ds; ds.ReadXml(xmlfilepath); here if you check the dataset viewer, you can see all the xml contents as tables. from there you can extract data and put it in database.

                  R Offline
                  R Offline
                  rockyl
                  wrote on last edited by
                  #8

                  I have implemented your suggestion, but facing some issues: Below is the code I have used: protected void Button1_Click(object sender, EventArgs e) { string path = @"D:\emp.xml"; string dsTable = ""; string connectionString = @"Server = DB\SQL2; Database = CWBDB; user = sa; password = sa"; DataSet ds = new DataSet("EMPDS"); ds.ReadXml(path); foreach (DataTable t in ds.Tables) { dsTable = t.ToString(); } SqlConnection con = new SqlConnection(connectionString); SqlDataAdapter da = new SqlDataAdapter(); da.TableMappings.Add("EMP", dsTable); if ((da.Update(ds))>0) { Label1.Text = "Uploaded the data successfully"; } else { Label1.Text = "Could not Upload the data"; } } But I see an exception: "Update unable to find TableMapping['Table'] or DataTable 'Table'." Please let me know what needs to be done for this!

                  Rakesh

                  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