Reputation: 217
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?
Upvotes: 0
Views: 1729
Reputation: 3356
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...
Upvotes: 2
Reputation: 887195
You need to execute a CREATE TABLE
statement on the server using a SqlCommand
. (DataAdapter
s will only populate tables, not create them)
Upvotes: 3