sSql = "SELECT * FROM tblTicketChanges"
Dim dtChg As DataTable = CreateDataTable(sSql, con)
I create the row in the code below and then add it to a datatable created above called dtChg.
Public Sub ADOSave2ChangeList(ByRef dt As DataTable, ByRef sFld As String, ByRef sNewValu As String, ByRef sOldValu As String, ByRef sTicketNo As String, ByRef sQualifier As String, ByRef sUser As String, ByRef dDate As Date, ByRef varTime As Date)
Dim r As DataRow = dt.NewRow ' Add new change record
r("ChangeTime") = String.Format("{0:MM/dd/yyyy} {1:hh:mm:ss}", dDate, varTime) ' Change date and time
r("Division") = gDiv ' Division number
r("Location") = gLocation ' Location id
r("TicketNo") = sTicketNo ' Ticket number
r("Qualifier") = NoNull(sQualifier) ' Qualifier
r("FieldName") = sFld ' Name of field that changed
r("OriginalValue") = sOldValu ' Original value
r("NewValue") = sNewValu ' New value
r("ChangedByUser") = sUser ' User id
Debug.WriteLine(String.Join(" ", r.ItemArray))
dt.Rows.Add(r) ' Save changes
gChanged = True ' Flag that change happened
End Sub
Is there a way to update or insert intothe Access table with the datatable dtChg without an sql insert statement? Or a way to just add that new row to the Access table without using the sql statement?
I got it working using the OleDbCommandBUilder:
Dim Builder As OleDbCommandBuilder = New OleDbCommandBuilder(da2)
Builder.GetUpdateCommand()
da2.UpdateCommand = Builder.GetUpdateCommand()
da2.Update(ds, "Changes")
I will add that I had to dimension a DataSet and I also named the DataTable "Changes". I not quite sure what is going on with the CommandBUilder but it seems pretty powerful. Going to read up on it.