copying dataset from asp.net webservice to local db

A

Aaron

Hi all,
I am trying to insert a whole dataset from my web service into a
SQLCE database. I am unsucessful so far. Any help is appreciated.
Here is what I have so far (the dataset is returned fine). I think my
problem lies in the fact that the rowstate is unchanged. I need it to
be add or even better yet, can it compare on its own??

Thanks, Aaron
-----------------------------------------------------------------------------

Public Sub SynchSQL2(ByVal ds As DataSet)
'connect locally to SQLCE
sqlConn = New SqlCeConnection(frmMain.connStr)
sqlConn.Open()
Dim dtSQL As DataTable
Dim dtCE As DataTable
Dim ds2 As DataSet = New DataSet
Dim cb As SqlCeCommandBuilder
Try

Dim dsupdate As New DataSet
'this is one table I am trying to "synch"
sqlDA = New SqlCeDataAdapter("select id,branch from
branch", sqlConn)

'create the commands
cb = New SqlCeCommandBuilder(sqlDA)
'set dataadapter insert to created command
sqlDA.InsertCommand = cb.GetInsertCommand()

sqlDA.Update(ds, "branch")

Catch ex As Exception
MsgBox(ex.Message)
End Try
 
W

William Ryan

Yes, if you don't change the data, then it won't be submitted to the DB.
You can call DataSet.HasChanges to test this, but from the code below, there
aren't any changes.

Without the commandbuilder though, you could iterate through the datarows
and submit them on your own (if you want everything to be added to the DB).
I'm guessin g that your ultimate goal is to query the WebService and get all
of that Data into your Database. You could also check beforehand to see if
it exists and compare states and all of that jazz.

I also think you could just walk the Rows Collection and set the Rowstate
manually, once this happens the commandbuilder should do it's thing. (I
haven't done it personally, but I'm pretty sure you can set the rowstate and
if so, it'll work).

HTH,

Bill
 
A

Alex Feinman [MVP]

Take a look at ImportDataSet sample at
http://www.alexfeinman.com/samples.asp
In it the dataset is loaded from disk (xml file) and is written via update
into SQL CE table. To use it with your web service make the web service to
return the DataSet variable and use this return value instead of loading
Dataset from disk.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top