Quantcast
Channel: Visual Studio General Questions forum
Viewing all articles
Browse latest Browse all 21115

WPF Save Dataset to Database

$
0
0

I have been pulling my hair out over this one, please help.

I have a simple database called ContactsDB that is bound to a DataGrid and I can't get any changes to save back to the database.  Right now just for testing purposes I have a save button that executes the c# function below.  I receive the 'update successful' dialog message but when I open the database in Access it is still the same (no saved changes).

                

        public void ButContactsSave(object sender, RoutedEventArgs e)
        {
            try
            {
                var dataset = new ContactsDB();
                var adapter = new ContactsDBTableAdapters.ContactsTableAdapter();

                adapter.Fill(dataset.Contacts);
                dataset.AcceptChanges();
                adapter.Update(dataset.Contacts);

                MessageBox.Show("Update successful");
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("Update failed");
            }
        }



Viewing all articles
Browse latest Browse all 21115

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>