Click to See Complete Forum and Search --> : can't persist dynamically created table


patrickcbrown
June 6th, 2002, 12:27 PM
Hi Everyone

I am having a bit of trouble trying to dynamically create tables, then have these persisted to a SQL Server database. I can see that the table is created and updated successfully in the dataset, it has all rows marked with a rowstate = Added, but when I call SqlDataAdapter.Update no new table is created. All other tables in the DB that I am using are updated successfully tho.

One note, I am dynamically creating these tables as needed, I have a table class that wraps up this type of table, in it's constructor after adding all columns and setting primary key, I Set up a SqlDataApdapter then SqlCommandBuilder.

This process works well for tables that existed prior to execution, but ...

Thank you for your time and ideas.
Patrick Brown

V. Lorenzo
June 7th, 2002, 03:45 AM
Hi:

The data adapter's update commands (created by the command builder when it's Update Method is called) does not create new tables if they don't exist in the database. They must be created explicitely by you using Transac-SQL code that can be executed using the method ExecuteNonQuery() from the Command object.

VictorL