Create a offline database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ericthered
    New Member
    • Nov 2006
    • 4

    #1

    Create a offline database

    Hi,
    I am trying to create an offline database in VB.NET 2005, both the online and offline database use SQL Server 2005.
    The code I am using seems to run OK with out an exception the DATASET has the records added, but the UPDATE will not update the offline database. (The offline database is empty before I start)

    Q1) what am I doing wrong?
    Q2) is there a better way of coping data to an offline SQL database?

    My code
    Code:
    Try
        da = New SqlDataAdapter(SQLcmd)
        conSQL.Open()
        da.Fill(dsOffLine, "TableName")
        dtOffLine= dsOffLine.Tables(0)
        Dim dsRow As DataRow
        Dim dsRowB As DataRow
    
    'Online DS loaded earlier
        For Each dsRow In frmMain.dsOnLine.Tables("TableName").Rows
            dsRowB = dtOffLine.NewRow()
            dsRowB.ItemArray = dsRow.ItemArray
            dtOffLine.Rows.Add(dsRowB)
            ''    Tried this instead of the above three rows
             '     dtOffLine.ImportRow(dsRow)
       Next
    
         dtOffLine.AcceptChanges()
         da.Update(dsOffLine, "TableName")
         conSQL.Close()
    Catch ex As Exception
         MsgBox(ex.ToString)
    End Try

    Thanks

    Eric
  • ericthered
    New Member
    • Nov 2006
    • 4

    #2
    Ok I have resolved the issue with two lines of code.

    Remove line 18
    Code:
    dtOffLine.AcceptChanges()
    And add a line after line 2

    Code:
    Dim builder As SqlCommandBuilder = New SqlCommandBuilder(da)
    Thanks

    Comment

    • kenobewan
      Recognized Expert Specialist
      • Dec 2006
      • 4871

      #3
      Well done! Thanks for sharing the solution.

      Comment

      Working...