简体   繁体   中英

save changes in a dataset to a table in a database

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]);
 ....
 SqlDataAdapter dataAdaptor = new SqlDataAdapter();
 new SqlCommandBuilder(dataAdaptor);
 dataAdaptor.Update(ds.Tables[0]);
 ....

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM