Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Storing disconnected Dataset

Status
Not open for further replies.

mansii

Programmer
Oct 18, 2002
641
ID
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:

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?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top