WebService & Datasets

A

a

Can someone please help me with the use of Datasets and Webservices to add
new reords to a database. I keep getting duplicate records added. When the
Update call returns, I have 2 copies of the new record in my dataset.

Also, I used to get strange things when using 'Autonumber' type fields. For
instance, if I delete the record with ID=10, then add a new record to the
dataset, I will get an error. Not sure why that stopped.

Here is my webservice code:

<WebMethod()> _
Public Function myGetDsTask() As dsTask
Dim ds As New dsTask
Me.daGroup.Fill(ds, "tblGroup")
Me.daTask.Fill(ds, "tblTask")
Return ds
End Function

<WebMethod()> _
Public Function myUpdateDsTask(ByVal ds As dsTask) As dsTask
Me.daGroup.Update(ds, "tblGroup")
Me.daTask.Update(ds, "tblTask")
Return ds
End Function

and here is the call from the form:

Public Shared Function GetDSTask() As wsTask.dsTask
If IsNothing(dsTask1) Then
dsTask1 = New wsTask.dsTask
ws.Url = strConnection
dsTask1.Merge(ws.myGetDsTask)
End If
Return dsTask1
End Function

Public Shared Function UpdateDSTask()
If dsTask1.HasChanges Then
ws.Url = strConnection
Dim dsTemp As New wsTask.dsTask
dsTemp.Merge(dsTask1.GetChanges)
dsTask1.Merge(ws.myUpdateDsTask(dsTemp))
End If
End Function

My dataset is set to AutoIncrementSeed = 0 and AutoIncrementStep = -1
What am I doing wrong?
 
M

[MSFT]

Hello,

The code in web methods seems to be great. I suggest you may add some code
in the client project, for example:

dsTemp.Merge(dsTask1.GetChanges)

Msgbox dsTemp.Table(0).Rows.Count

dsTask1.Merge(ws.myUpdateDsTask(dsTemp))

You may add one new record and check how many records there is in dsTemp,
and then check how many records will be added to the database.

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
A

a

I have tried that and this is what seems to happen. I add the new row to
dsTask1 (Count now = 4), so I have ID=1, ID=2, ID=3, and the new row ID = 0
(AutoIncrementSeed = 0 and AutoIncrementStep = -1. I had to set up the
AutoIncrment stuff this way, because if I were to delete ID=3, then re-fill
the DS and let it add a new record, it would reuse ID=3 and crash on saving
to the DB.)

Then, after my call to:
dsTask1.Merge(ws.myUpdateDsTask(dsTemp))

dsTask1 has the record from the DB (with the new ID=4), as well as the
record with ID=0. How would I then remove the record with ID=0?
AcceptChanges? Better / Diff code to save the dataset? In the form or in
the WebService?

Thanks!

Kevin


<WebMethod()> _
Public Function myGetDsTask() As dsTask
Dim ds As New dsTask
Me.daGroup.Fill(ds, "tblGroup")
Me.daTask.Fill(ds, "tblTask")
Return ds
End Function

<WebMethod()> _
Public Function myUpdateDsTask(ByVal ds As dsTask) As dsTask
Me.daGroup.Update(ds, "tblGroup")
Me.daTask.Update(ds, "tblTask")
Return ds
End Function

and here is the call from the form:

Public Shared Function GetDSTask() As wsTask.dsTask
If IsNothing(dsTask1) Then
dsTask1 = New wsTask.dsTask
ws.Url = strConnection
dsTask1.Merge(ws.myGetDsTask)
End If
Return dsTask1
End Function

Public Shared Function UpdateDSTask()
If dsTask1.HasChanges Then
ws.Url = strConnection
Dim dsTemp As New wsTask.dsTask
dsTemp.Merge(dsTask1.GetChanges)
dsTask1.Merge(ws.myUpdateDsTask(dsTemp))
End If
End Function
 
M

[MSFT]

Hi Kevin,

I think there two ways to get around the problem.

1. After the update, you can fill the dataset "dsTask1" again to get the
updated ID value from the database.
2. before the merge method "dsTask1.Merge(ws.myGetDsTask)", delete some
rows from the dstask1 whose rowstate is not unchanged. And then call
acceptchanges method.

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

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