update tabledefinition using dataadapter and datacolumn

B

Binder

Hi everybody!

I'm trying use the datacolumn class to create new columns in a datatable
object and submit the new created column to the database (Access 2000).

Here's the code:
Sub Main()
Dim oconn As New OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;
Data Source=C:\test.mdb")
Dim adapter As New OleDbDataAdapter("SELECT * FROM Cities", oconn)

Dim mydt As New DataTable
Dim nCol As New DataColumn

adapter.Fill(mydt)

With nCol
.Caption = "Newcolumn"
.DataType = OleDbType.Boolean.GetType
End With

'Add column to Datatable
mydt.Columns.Add(nCol)

'Write changes to database
adapter.Update(mydt)
ReadLine()
End Sub

I know I could use "ALTER TABLE ALTER COLUMN" commands as well, but is there
any way to create/update columns to a table in a database using ADO.NET
(without using DAO or ADOX)

Thanks for your efforts!

wkr binder
 
M

Mary Chipman [MSFT]

The DataAdapter will only write changes to the data to the database,
it won't create new columns in a table. You'd need to execute SQL DDL
via a command object or use DAO/ADOX in a separate operation.

--Mary
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top