New Columns added to Bound DataGrid not updating

Jun 18, 2009 at 3:48 AM

I am populating a dataGrid from a database.  The problem is that as the database will update properly with every edit using update.  But, when I add a column to the dataGrid in the code behind it will not update the database properly.  I can't design anything in xaml because the column rows change and vary.  It all has to be done in the code behind.

Jun 23, 2009 at 5:26 AM

What is triggering the update to the database?

Jun 23, 2009 at 5:01 PM

dataAdapter.Update(dataSet, dt.TableName);

Jun 23, 2009 at 10:14 PM

Could you supply a little more code so we can understand the context.  What do the bindings on the DataGridColumns look like?  What triggers the call to dataAdpator.Update() from the UI?

Jun 25, 2009 at 3:55 AM
Edited Jun 25, 2009 at 3:56 AM

This is just a test program using a button to test updating. No matter which way I add a column to the database the DataGrid will allow me to enter data but when clicking the button it does not update the database. Also you will notice that it is a sqlite database but it is ado and It hasn't given me any trouble yet.


                    cmd = new SQLiteCommand("ALTER TABLE [" + tablename + "] ADD [" + field + "]" + fieldtype, sqliteconnection);
to add a column works if I call LoadTable again after but that's kind of a cludge fix isn't it?

Any Ideas??????

        private void button5_Click(object sender, RoutedEventArgs e)
            dataAdapter.Update(dataSet, "COURSE 1   05/01/1990");
        private void LoadTable()

                dataSet = new DataSet();
                string connString = String.Format("Data Source={0};New=False;Version=3", @"D:\icon\DEMO COMPANY\ANYTOWN USA\Pulp Mill\TANK-125\data.db");

                SQLiteConnection sqlconn = new SQLiteConnection(connString);

                string CommandText = String.Format("Select * from [{0}];", "COURSE 1   05/01/1990");

                dataAdapter = new SQLiteDataAdapter(CommandText, sqlconn);
                SQLiteCommandBuilder builder = new SQLiteCommandBuilder(dataAdapter);
                this.dataAdapter.Fill(dataSet, "COURSE 1   05/01/1990");
                dataGrid1.ItemsSource = dataSet.Tables["COURSE 1   05/01/1990"].DefaultView;
            catch (SQLiteException sqlex)
            catch (Exception ex)


Jun 30, 2009 at 5:46 PM


Jul 6, 2009 at 1:38 PM

Were there any ideas on this subject?

Jul 7, 2009 at 9:49 PM

It looks like it may be a problem with the SQL adapter.  Unfortunately we're not too familiar with the intricacies of SQL, so you may want to try posting this question on the MSDN SQL forums.