By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,032 Members | 1,147 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,032 IT Pros & Developers. It's quick & easy.

add columns (modify) Datatable AND source MDB

P: n/a
I have a program that runs a query ("Select * From MyTable") on an Access
Database and saves the results in a DataTable (see function, below). The
program then adds columns to the DataTable, then updates rows in the
DataTable with data for the new columns. I can write the DataTable to XML
and see the changes I have made.

How can I get the changes I have made to my DataTable to apply to my Access
Database?

HERE IS THE CODE USED TO GET THE DATATABLE:

Private Function DoSQLQuery(ByVal sQuery As String) As DataTable

Dim oDbReader As SqlDataReader
Dim oDataAdapter As SqlDataAdapter

Dim oDbCommand As SqlCommand
If gbForeignQueryBuilder Then
goDataTable = New DataTable("Query")
Else
goDataTable.Clear()
End If

gSqlConnection = New SqlConnection(gsConnectionString)

Try
gSqlConnection.Open()
oDbCommand = New SqlCommand(sQuery, gSqlConnection)
oDataAdapter = New SqlDataAdapter(oDbCommand)
oDataAdapter.Fill(goDataTable)
Return goDataTable
Catch e As Exception
Const ERR_IN_QUERY = 1002
Err.Raise(ERR_IN_QUERY, Me.CLASS_NAME, "Error in Query: " & e.ToString())
Finally
If Not (oDbReader Is Nothing) Then
oDbReader.Close()
End If
If Not (gSqlConnection Is Nothing) Then
gSqlConnection.Close()
End If
End Try

End Function
Feb 13 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
CMM
AFAIK you're going to have to execute DDL commands to do this. The
DataAdapter doesn't modify schemas. This isn't hard... just as you add them
to the Dataset, execute ALTER TABLE commands on the database.

--
-C. Moya
www.cmoya.com
Feb 13 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.