Dataset, Autoincrement, and WebService Issues

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, one
with the dataset assigned ID, and on that comes back from the DB (my update
stored procedure is set to refresh the 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? Do I 'need' to have a non-identity primary key? What
will happen when I introduce 'relationships' to the dataset.

THanks gang!

Kevin
 
V

Val Mazur

Hi,

Based on an error message it means that your dataadapter tries insert a new
record, which has exact same primary key, which already exists in a
database. For example, if your dataset creates new row with the autonumber
value, which already exists in a database, then your insert will fail. I
think it could happen after you merged dataset. Hard to say what could be
wrong, but try to debug code and see what happens after you merged data.
Check if you do not get duplicated values for the autonumber
 
W

William Ryan eMVP

Hi a:

Have you verfied what you are sending to it. It's possible that something
other than 10 is being sent to the DB (or a negative number which should
never raise a concurrency exception)?

It also looks like you have two calls to update. Which one is blowing up
the first or the second one?
 
A

a

I found some info about adding code to the DataAdapter's RowUpdated event to
eliminate the issue.

If e.StatementType = StatementType.Insert Then
e.Status = UpdateStatus.SkipCurrentRow

End If

In hindsight, changing the AutoIncremet Step and Seed to (-1) fixed the
error, and adding this code to the dataadapter fixed my other issue, where
after the Call to the Webservice to update, the -1 ID record was in the
dataset along with the newly added record from the DB (with its new ID
number)

THanks!

Kevin
 
K

Kevin Yu [MSFT]

Hi Kevin,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that your DataSet update throught a web
service creates duplicated rows. If there is any misunderstanding, please
feel free to let me know.

It was nice to hear that you have had the problem resolved. Yes,
generally, we set the AutoIncrement Seed and Step to -1, so the newly
inserted rows will never duplicate with rows in the data source. Here are
two KB articles about updating the dataset through a web service. HTH.

http://support.microsoft.com/default.aspx?scid=kb;en-us;308056

http://support.microsoft.com/default.aspx?scid=kb;en-us;313540

If anything is unclear, please feel free to reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
K

Kevin Yu [MSFT]

Hi Kevin

I'd like to know if this issue has been resolved yet. Is there anything
that I can help. I'm still monitoring on it. If you have any questions,
please feel free to post them in the community.

Kevin Yu
=======
"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