0

I need some help showing me how to go about storing/saving changes made in a dataset back to the table(s) in the database. I'm using C# with windows forms on visual studio. Database is a local SQL Server.

I have managed to get the data to the data set but cannot save changes. the below is not saving to the database. ds is my dataset.

ds.AcceptChanges();

SqlDataAdapter dataAdaptor = new SqlDataAdapter();
dataAdaptor.Update(ds.Tables[0]);
  • 2
    Possible duplicate of [Saving Dataset to database](http://stackoverflow.com/questions/11608546/saving-dataset-to-database) and several dozen other existing questions. Please make at least a basic effort to search for existing questions before posting a new one here. – Ken White Jun 17 '16 at 02:31
  • Thanks Ken, and everyone who answered, I have actually been searching for weeks on this site and all over the internet, but I can't seem to get my hand on the write leads, maybe there is a significant gap in my understanding somewhere... So I thought to ask the question generally, maybe the question was not clear enough. I was looking for a theoretical answer not necessarily a piece of code, I have read on msdn about all types of datasets and their adapters, but still cannot get anything to work in my case. I do realise it's a very broad question but wanted some help narrowing it down. – Naiem Ayoub Aug 01 '16 at 03:09

2 Answers2

-1
 ....
 SqlDataAdapter dataAdaptor = new SqlDataAdapter();
 new SqlCommandBuilder(dataAdaptor);
 dataAdaptor.Update(ds.Tables[0]);
 ....
George Poliovei
  • 1,009
  • 10
  • 12
-1

Have you set up all your Command properties for Select, Insert, Update, & Delete? These need to be configured before you can use the SqlDataAdaptor

Also see this link. The SqlCommandBuilder can automatically generate the command properties for you as long as you have your Select command set.

Stunshaw
  • 36
  • 1
  • 6