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(ByVa l sQuery As String) As DataTable
Dim oDbReader As SqlDataReader
Dim oDataAdapter As SqlDataAdapter
Dim oDbCommand As SqlCommand
If gbForeignQueryB uilder Then
goDataTable = New DataTable("Quer y")
Else
goDataTable.Cle ar()
End If
gSqlConnection = New SqlConnection(g sConnectionStri ng)
Try
gSqlConnection. Open()
oDbCommand = New SqlCommand(sQue ry, gSqlConnection)
oDataAdapter = New SqlDataAdapter( oDbCommand)
oDataAdapter.Fi ll(goDataTable)
Return goDataTable
Catch e As Exception
Const ERR_IN_QUERY = 1002
Err.Raise(ERR_I N_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
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(ByVa l sQuery As String) As DataTable
Dim oDbReader As SqlDataReader
Dim oDataAdapter As SqlDataAdapter
Dim oDbCommand As SqlCommand
If gbForeignQueryB uilder Then
goDataTable = New DataTable("Quer y")
Else
goDataTable.Cle ar()
End If
gSqlConnection = New SqlConnection(g sConnectionStri ng)
Try
gSqlConnection. Open()
oDbCommand = New SqlCommand(sQue ry, gSqlConnection)
oDataAdapter = New SqlDataAdapter( oDbCommand)
oDataAdapter.Fi ll(goDataTable)
Return goDataTable
Catch e As Exception
Const ERR_IN_QUERY = 1002
Err.Raise(ERR_I N_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
Comment