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. Exception with DataAdapter.Update ! [modified]

Exception with DataAdapter.Update ! [modified]

Scheduled Pinned Locked Moved ASP.NET
databasesysadminxmlhelpannouncement
3 Posts 2 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 have an xml file with employee data and need to uplaod its content to the database. For this I have used dataset.ReadXml method and then I am using the dataadapter.update method to upload the content of the dataset to the database. Here is the code: 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 help! -- modified at 8:15 Wednesday 11th April, 2007

    Rakesh

    S 1 Reply Last reply
    0
    • R rockyl

      Hi, I have an xml file with employee data and need to uplaod its content to the database. For this I have used dataset.ReadXml method and then I am using the dataadapter.update method to upload the content of the dataset to the database. Here is the code: 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 help! -- modified at 8:15 Wednesday 11th April, 2007

      Rakesh

      S Offline
      S Offline
      Sandeep Akhare
      wrote on last edited by
      #2

      rockyl wrote:

      foreach (DataTable t in ds.Tables) { dsTable = t.ToString(); }

      What are you trying do here ? i think it will overwrite in each loop

      Thanks and Regards Sandeep If you want something you never had, do something you have never done!

      R 1 Reply Last reply
      0
      • S Sandeep Akhare

        rockyl wrote:

        foreach (DataTable t in ds.Tables) { dsTable = t.ToString(); }

        What are you trying do here ? i think it will overwrite in each loop

        Thanks and Regards Sandeep If you want something you never had, do something you have never done!

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

        da.TableMappings.Add("EMP", dsTable); The above statement of my code makes a mapping between database table and dataset table, the first parameter is the database table name and the 2nd paramaeter is dataset table name. So I am getting the table name from the dataset and passing to it so that a mapping may occur between the database table and the dataset table. In short I will explain what I am trying to do. Theres an xml file consisting of Employee data, I need to upload this xml content to the Database. For this I have used the Dataset.fill(xmlpath) and then using the dataadapter for updating the data to the database. Now u can see my previous code and get clear understanding.

        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