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. C#
  4. Dataset Accept change is not working

Dataset Accept change is not working

Scheduled Pinned Locked Moved C#
databasehelpquestionannouncement
2 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.
  • S Offline
    S Offline
    Shahzad Aslam
    wrote on last edited by
    #1

    I am trying to copy one dataset to another and calling acceptchanges to update database but it is not working although not giving any error. here is the code. SqlDataAdapter da2 = new SqlDataAdapter("SELECT * FROM " + DestinationTableName, consql); DataSet dsDest = new DataSet(); dsDest.CaseSensitive = false; da2.Fill(dsDest, DestinationTableName); dsDest.Tables[0].TableName = DestinationTableName; DataTable dt = new DataTable(); dt.TableName = DestinationTableName; foreach (DataRow dr in dsSource.Tables[0].Rows) { DataRow drdata= dsDest.Tables[0].NewRow(); foreach (DataColumn dc in dsSource.Tables[0].Columns) { drdata[dc.ColumnName] = dr[dc.ColumnName]; } dsDest.Tables[0].Rows.Add(drdata); dsDest.AcceptChanges(); da2.Update(dsDest.Tables[0]); } Whats wrong with above code..?

    L 1 Reply Last reply
    0
    • S Shahzad Aslam

      I am trying to copy one dataset to another and calling acceptchanges to update database but it is not working although not giving any error. here is the code. SqlDataAdapter da2 = new SqlDataAdapter("SELECT * FROM " + DestinationTableName, consql); DataSet dsDest = new DataSet(); dsDest.CaseSensitive = false; da2.Fill(dsDest, DestinationTableName); dsDest.Tables[0].TableName = DestinationTableName; DataTable dt = new DataTable(); dt.TableName = DestinationTableName; foreach (DataRow dr in dsSource.Tables[0].Rows) { DataRow drdata= dsDest.Tables[0].NewRow(); foreach (DataColumn dc in dsSource.Tables[0].Columns) { drdata[dc.ColumnName] = dr[dc.ColumnName]; } dsDest.Tables[0].Rows.Add(drdata); dsDest.AcceptChanges(); da2.Update(dsDest.Tables[0]); } Whats wrong with above code..?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You are calling methods in wrong sequence. You need to first call Update() of DataAdapter and then you can call AcceptChanges() of your dataset to reflect changes to database.

       dsDest.Tables\[0\].Rows.Add(drdata);
       da2.Update(dsDest.Tables\[0\]);
       dsDest.AcceptChanges();
      

      For further help refer following links. http://msdn.microsoft.com/en-us/library/system.data.common.dataadapter.update.aspx[^] http://www.akadia.com/services/dotnet_update_form.html[^] Hope this will help!

      Jinal Desai - LIVE Experience is mother of sage....

      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