By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,143 Members | 1,919 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,143 IT Pros & Developers. It's quick & easy.

Create a offline database

P: 4
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
Expand|Select|Wrap|Line Numbers
  1.  
  2. Try
  3.     da = New SqlDataAdapter(SQLcmd)
  4.     conSQL.Open()
  5.     da.Fill(dsOffLine, "TableName")
  6.     dtOffLine= dsOffLine.Tables(0)
  7.     Dim dsRow As DataRow
  8.     Dim dsRowB As DataRow
  9.  
  10. 'Online DS loaded earlier
  11.     For Each dsRow In frmMain.dsOnLine.Tables("TableName").Rows
  12.         dsRowB = dtOffLine.NewRow()
  13.         dsRowB.ItemArray = dsRow.ItemArray
  14.         dtOffLine.Rows.Add(dsRowB)
  15.         ''    Tried this instead of the above three rows
  16.          '     dtOffLine.ImportRow(dsRow)
  17.    Next
  18.  
  19.      dtOffLine.AcceptChanges()
  20.      da.Update(dsOffLine, "TableName")
  21.      conSQL.Close()
  22. Catch ex As Exception
  23.      MsgBox(ex.ToString)
  24. End Try
  25.  

Thanks

Eric
May 17 '07 #1
Share this Question
Share on Google+
2 Replies


P: 4
Ok I have resolved the issue with two lines of code.

Remove line 18
Expand|Select|Wrap|Line Numbers
  1. dtOffLine.AcceptChanges()
  2.  
And add a line after line 2

Expand|Select|Wrap|Line Numbers
  1. Dim builder As SqlCommandBuilder = New SqlCommandBuilder(da) 
  2.  
Thanks
May 18 '07 #2

kenobewan
Expert 2.5K+
P: 4,871
Well done! Thanks for sharing the solution.
May 18 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.