views:

35

answers:

2

I am trying to add a datatable to a database. Here's what I've been trying:

    Dim newDataTable As DataTable = New DataTable("Example")
    VocabularyDataSet.Tables.Add(newDataTable)
    SqlDataAdapter1.Fill(VocabularyDataSet.Tables("Example"))

I've tried various incarnations of Fill and Update. But the tables will not save on the database!

Any ideas?

+3  A: 

You need to execute a CREATE TABLE statement on the server using a SqlCommand. (DataAdapters will only populate tables, not create them)

SLaks
+2  A: 

try to use create table with a SQLCommand or OLECommand:


Dim cnn as SqlConnection = new SqlConnection("")
Dim cmd as SqlCommand = new SqlCommand("Create Table TableName (ID int, Name nvarchar(50), constraint PK_Table1 Primary Key (ID))", cnn)

cnn.Open()
cmd.ExecuteNonQuery()
cnn.Close()

With datatable and dataset variables, you can just create table variables... not to attach them to your database...

Dr TJ