Data table not updating database

OFGemini
OFGemini used Ask the Experts™
on
I am using a data table to update my database and, I am populating a dataset, then using table adapters to update the database but, nothing seems to be happening.  Where could the possible errors be?
Also no SQL errors are showing..
Thanks for the help!
public MainWindow()
        {
            InitializeComponent();
            dataset = ((Icon_Database_Utility.IconUtilityDataSet)(this.FindResource("IconUtilityDataSet")));
            
            tableAdapterManager = new TableAdapterManager();
            tableAdapterManager.Connection = new SqlConnection(Icon_Database_Utility.Properties.Settings.Default.IconUtilityConnectionString);
            tableAdapterManager.IconInfoTableAdapter = new IconInfoTableAdapter();
            tableAdapterManager.IconPathsTableAdapter = new IconPathsTableAdapter();
            if (!TestMode)
            {
                System.Data.SqlClient.SqlConnection con;
                con = new SqlConnection();
                con.ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\IconUtility.mdf;Integrated Security=True;User Instance=True";
                con.Open();


                tableAdapterManager.Connection.Open();
                tableAdapterManager.IconInfoTableAdapter.Fill(dataset.IconInfo);
                tableAdapterManager.IconPathsTableAdapter.Fill(dataset.IconPaths);
                tableAdapterManager.Connection.Close();
            }

        private void button1_Click_1(object sender, RoutedEventArgs e)
        { 
           // update database
            start = DateTime.Now;
            if (!TestMode)
            {
                tableAdapterManager.Connection.Open();
                tableAdapterManager.UpdateAll(dataset);
                tableAdapterManager.Connection.Close();
            }
}

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2012
Top Expert 2008
Commented:
There are possibilities:

1) Using AcceptChanges at the wrong time, which will reset the DataRow states for a DataTable back to Unmodified.

2) DataTable doesn't have any changes--check with DataTable.GetChanges, or DataSet.GetChanges().

Author

Commented:
Thanks for the quick response!

both options checkout ok as far as I can tell....
only the designerfile is using AcceptChanges

my debugger shows changes with data table.GetChanges and DataSet.GetChanges()....
Most Valuable Expert 2012
Top Expert 2008

Commented:
You have a condition here (!TestMode), that you need debug:

if (!TestMode)
{
      tableAdapterManager.Connection.Open();
      tableAdapterManager.UpdateAll(dataset);
      tableAdapterManager.Connection.Close();
}

You also need to make sure that you are looking in the correct database, that is referenced in the connection (simple problem that is often overlooked).
Success in ‘20 With a Profitable Pricing Strategy

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
I seems to work because it takes a while to do the UpdateAll(dataset)

also in my example I was creating to connections and so I removed this one...

                System.Data.SqlClient.SqlConnection con;
                con = new SqlConnection();
                con.ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\IconUtility.mdf;Integrated Security=True;User Instance=True";
                con.Open();
Most Valuable Expert 2012
Top Expert 2008

Commented:
That doesn't indicate if you are still having the problem.

Author

Commented:
sorry yes I am still having the problem...

Author

Commented:
My MDF file property copy to out put need to be changed to copy if newer.

Thanks for trying....

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial