updating database from dataset

Thread Solved

Join Date: Dec 2007
Posts: 205
Reputation: carobee is an unknown quantity at this point 
Solved Threads: 11
carobee carobee is offline Offline
Posting Whiz in Training

updating database from dataset

 
0
  #1
Feb 6th, 2009
How do i update a database from dataset.
  1. SqlDataAdapter.Update()
is not working
Last edited by carobee; Feb 6th, 2009 at 12:49 am.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 104
Reputation: Aneesh_Argent is an unknown quantity at this point 
Solved Threads: 18
Aneesh_Argent Aneesh_Argent is offline Offline
Junior Poster

Re: updating database from dataset

 
0
  #2
Feb 6th, 2009
Try using the SqlCommandBuilder Class like this

  1.  
  2. SqlCommandBuilder mySqlCommandBuilder = new SqlCommandBuilder(mySqlDataAdapter);
  3.  
  4. mySqlDataAdapter.Update(myDataSet, "myTableName");
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 205
Reputation: carobee is an unknown quantity at this point 
Solved Threads: 11
carobee carobee is offline Offline
Posting Whiz in Training

Re: updating database from dataset

 
0
  #3
Feb 6th, 2009
Tried that but its not working. Do i have to set the update,delete and insert command?


Originally Posted by Aneesh_Argent View Post
Try using the SqlCommandBuilder Class like this

  1.  
  2. SqlCommandBuilder mySqlCommandBuilder = new SqlCommandBuilder(mySqlDataAdapter);
  3.  
  4. mySqlDataAdapter.Update(myDataSet, "myTableName");
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 104
Reputation: Aneesh_Argent is an unknown quantity at this point 
Solved Threads: 18
Aneesh_Argent Aneesh_Argent is offline Offline
Junior Poster

Re: updating database from dataset

 
0
  #4
Feb 6th, 2009
Can u post your full code here.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 205
Reputation: carobee is an unknown quantity at this point 
Solved Threads: 11
carobee carobee is offline Offline
Posting Whiz in Training

Re: updating database from dataset

 
0
  #5
Feb 6th, 2009
Here is the code
  1. SqlDataAdapter da = new SqlDataAdapter("select * from mytable",strCon);
  2. DataSet ds = new DataSet();
  3. da.Fill(ds);
  4.  
  5. GridView2.DataSource = ds;
  6. GridView2.DataBind();
  7. SqlCommandBuilder m_cd = new SqlCommandBuilder(da);
  8. string UpdateCommand = m_cd.GetUpdateCommand().CommandText;
  9.  
  10. da.Update(ds, "mytable");
Last edited by carobee; Feb 6th, 2009 at 3:11 am.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 104
Reputation: Aneesh_Argent is an unknown quantity at this point 
Solved Threads: 18
Aneesh_Argent Aneesh_Argent is offline Offline
Junior Poster

Re: updating database from dataset

 
0
  #6
Feb 6th, 2009
Try this:
  1. SqlDataAdapter da = new SqlDataAdapter("select * from mytable",strCon);
  2. SqlCommandBuilder m_cd = new SqlCommandBuilder(da);
  3. da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
  4.  
  5. DataSet ds = new DataSet();
  6. da.Fill(ds);
  7.  
  8. GridView2.DataSource = ds;
  9. GridView2.DataBind();
  10.  
  11. string UpdateCommand = m_cd.GetUpdateCommand().CommandText;
  12.  
  13. da.Update(ds, "mytable");
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 205
Reputation: carobee is an unknown quantity at this point 
Solved Threads: 11
carobee carobee is offline Offline
Posting Whiz in Training

Re: updating database from dataset

 
0
  #7
Feb 6th, 2009
Throwing an error as
  1. Update unable to find TableMapping['mytable'] or DataTable 'mytable'

Originally Posted by Aneesh_Argent View Post
Try this:
  1. SqlDataAdapter da = new SqlDataAdapter("select * from mytable",strCon);
  2. SqlCommandBuilder m_cd = new SqlCommandBuilder(da);
  3. da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
  4.  
  5. DataSet ds = new DataSet();
  6. da.Fill(ds);
  7.  
  8. GridView2.DataSource = ds;
  9. GridView2.DataBind();
  10.  
  11. string UpdateCommand = m_cd.GetUpdateCommand().CommandText;
  12.  
  13. da.Update(ds, "mytable");
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 104
Reputation: Aneesh_Argent is an unknown quantity at this point 
Solved Threads: 18
Aneesh_Argent Aneesh_Argent is offline Offline
Junior Poster

Re: updating database from dataset

 
0
  #8
Feb 6th, 2009
da.Update(ds, "mytable");

Here "mytable" should be replace by your tablename. I have given it just as an example. Since your Dataset contains only one table you can use this instead.

da.Update(ds.Tables[0]);
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 205
Reputation: carobee is an unknown quantity at this point 
Solved Threads: 11
carobee carobee is offline Offline
Posting Whiz in Training

Re: updating database from dataset

 
0
  #9
Feb 6th, 2009
i had replaced it with my table name.Still it was showing that error. while changing it to
  1. da.Update(ds.Tables[0]);
as you suggested, no updation was done on the table
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 205
Reputation: carobee is an unknown quantity at this point 
Solved Threads: 11
carobee carobee is offline Offline
Posting Whiz in Training

Re: updating database from dataset

 
0
  #10
Feb 17th, 2009
finally i hv found the solution. i was actually tryng to update MS access. for that you have to check the permissions of the table and give proper permissions
Last edited by carobee; Feb 17th, 2009 at 1:48 am.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 1366 | Replies: 10
Thread Tools Search this Thread



Tag cloud for ASP.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC