Framework 1.1
Working Environment:
- Heavy data traffic
- Sudden electricity shut down
Strategy:
- Store current documents in local machine
- Save it to database server when user finished keying all documents.
Read all local tables and store them in a local dataset:
Result:
- No error occurs
- No records updated
I used to manually loop through all records and update/insert it manually. Now I want to start using DataAdapter.
Did I miss something here?
Working Environment:
- Heavy data traffic
- Sudden electricity shut down
Strategy:
- Store current documents in local machine
- Save it to database server when user finished keying all documents.
Read all local tables and store them in a local dataset:
Code:
Dim LeftLocalSet As DataSet
LeftLocalSet = New DataSet("LeftLocal")
Dim ntbl As DataTable
Dim cmd As OleDb.OleDbCommand
Dim TblNm As String
Dim da As OleDb.OleDbDataAdapter
Try
For i As Integer = 0 To 2
TblNm = "Table" & i.ToString
ntbl = New DataTable(TblNm)
cmd = New OleDb.OleDbCommand("SELECT * FROM " & TblNm, LocalDataConn)
da = New OleDbDataAdapter(cmd)
da.Fill(ntbl)
LeftLocalSet.Tables.Add(ntbl)
Next
Catch ex As Exception
MsgBox(ex.ToString)
End Try
Try
Dim Result As Integer = _
UploadLeftOver(LeftLocalSet)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
Code:
Public Function UploadLeftOver(ByVal ds As DataSet) As Integer
Dim c As OdbcCommand
Dim ret As Integer
Dim DA As New OdbcDataAdapter
Try
If Not rDataConn.State = ConnectionState.Open Then rDataConn.Open()
Dim DS2Upload As DataSet = ds.Copy
For Each tbl As DataTable In DS2Upload.Tables
c = New OdbcCommand
c.CommandText = "select * from dba." & tbl.TableName
c.Connection = rDataConn
DA = New OdbcDataAdapter
DA.SelectCommand = c
Dim cmdbldr As New OdbcCommandBuilder(DA)
DA.DeleteCommand = cmdbldr.GetDeleteCommand
DA.UpdateCommand = cmdbldr.GetUpdateCommand
DA.InsertCommand = cmdbldr.GetInsertCommand
ret += DA.Update(tbl)
Next
Catch ex As Exception
MsgBox(ex.ToString)
Finally
DA = Nothing
If Not rDataConn.State = ConnectionState.Closed Then rDataConn.Close()
End Try
Return ret
End Function
Result:
- No error occurs
- No records updated
I used to manually loop through all records and update/insert it manually. Now I want to start using DataAdapter.
Did I miss something here?