0

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?

1

2 Answers 2

3

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

Sign up to request clarification or add additional context in comments.

Comments

2

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...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.