Christineeve
Programmer
Below is an example of one of my update procedures. I'd like to capture the changes after update with something like, haschanges or getchanges.
Working with the code as it is, I'm sure it's pretty bad, can I call a procedure that will create a datatable with the updates? Then from there I'd like to write it to a table in my access database.
I've followed the examples here, but I can't seem to figure out how to make it worth with my procedure.
Would any experts be able to help me?
Working with the code as it is, I'm sure it's pretty bad, can I call a procedure that will create a datatable with the updates? Then from there I'd like to write it to a table in my access database.
I've followed the examples here, but I can't seem to figure out how to make it worth with my procedure.
Would any experts be able to help me?
Code:
Public Shared Sub UpdateBank()
'This procedure executes both select and insert statement.
Dim cmdUpdBank As New OleDbCommand
Dim daUpdBank As New OleDbDataAdapter
Dim dsUpdBank As New DataSet
Dim dtUpdBank As New DataTable
Dim m_rowPosition As Integer = 0
Dim myBuilder As OleDbCommandBuilder = New OleDbCommandBuilder(daUpdBank)
Try
Using oConn As New OleDbConnection
Dim DataSource As String = frmAhmed.gMyDataSource
'create a connection string
oConn.ConnectionString = ("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & DataSource & ";User ID=Admin;Password=;")
oConn.Open()
If oConn.State = ConnectionState.Open Then
Dim sSQL = "SELECT * FROM tblEmpBankInfo Where fk_EmpInfoID =" & "('" & Trim(frmAhmed.txtEmpID.Text) & "')"
'Where fk_EmpInfoID = " & Trim(CInt(frmAhmed.txtPsEmplyNo.Text))
'Select all from the database and determine if the txtEmplyNo exists.
cmdUpdBank = oConn.CreateCommand
';cmdUpdBank1 = oConn.CreateCommand
cmdUpdBank.CommandText = sSQL
daUpdBank.SelectCommand = cmdUpdBank
daUpdBank.Fill(dsUpdBank, "UpdBank")
dtUpdBank = dsUpdBank.Tables("UpdBank")
myBuilder.GetUpdateCommand()
daUpdBank.UpdateCommand = myBuilder.GetUpdateCommand()
If dtUpdBank.Rows.Count > 0 Then
dtUpdBank.Rows(m_rowPosition)("empBankRoutingNo") = Trim(frmAhmed.txtBankRtNum.Text)
dtUpdBank.Rows(m_rowPosition)("empBankAccountNo") = (frmAhmed.txtBankAcctNum.Text)
dtUpdBank.Rows(m_rowPosition)("empDateMod") = Trim(frmAhmed.mtxtBankLstMod.Text)
daUpdBank.Update(dtUpdBank)
'Here I'd like to call the
'the procedure to create the datatable
'that will write to my MS Access Db.
audBankChanges()
Else
ExecuteBank()
End If
Else
MsgBox("Employee record cannot be found. Verify if data has been entered for this employee")
'MsgBox("connection state = " & oConn.State)
End If
MsgBox("Employee Record modified.", MsgBoxStyle.OkOnly, "Update Successful")
oConn.Close()
oConn.Dispose()
End Using
Catch ex As Exception
MsgBox("Error: " & ex.Source & ": " & ex.Message, MsgBoxStyle.OkOnly, "Error!")
End Try
End Sub