Using VB 2010 and SQL Server 2008:
I am able to insert new rows, delete rows, and update data in a datatable, and use a data adapter to update the database without any issues. When I try to add new columns, the column appears in the data table, but it does not update to the database. I currently am using the DataAdapter.Update(DataTable) Method.
My code is as follows:
Dim dcNewColumn As New DataColumn
dcNewColumn.ColumnName = strClassColumnName
m_DataTable.Columns.Add(dcNewColumn)
m_DataTable.Row(intCurrentRow).Item(strClassColumnName) = strClassName
dcNewColumn = Nothing
m_DA.Update(m_DataTable)
Is there a different method to updating the database when inserting new columns?
You are looking for the
ALTER TABLEsql command.Or the SQLDMO Columns Collection (Please check the notice at the start of the page)
An ALTER TABLE Command to add a column could be coded in this way