Hi Earl,
You are probably not reading timestamp of newly inserted record (for Insert
there is no check of concurrency, while for update there is).
--
Miha Markic [MVP C#] - RightHand .NET consulting & development
www.rthand.com
Blog:
http://cs.rthand.com/blogs/blog_with_righthand/
SLODUG - Slovene Developer Users Group
www.codezone-si.info
"Earl" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Not sure what I'm overlooking here, but banging my head against the wall
> for several hours is long enough. Hopefully someone can see what is
> causing this concurrency exception.
>
> I do NOT get a concurrency error if I do an Update without any prior
> events occuring (Delete or Insert). However, if I add a new record and
> immediately do an Update on the same record, I then get a DBconcurrency
> exception. Indeed, if I add a new record, do an Update on a different row,
> then come back and do an update on the new row, I STILL get a concurrency
> exception.
>
> All this led me to believe the stored procedure was not returning the
> previous identity value on the Insert. Nope, that looks correct. I even
> examined the parameters collection and trimmed that down to where I was
> just comparing to ID and timestamp in the SP, with the same exception.
>
>
> **********************************************
> Private Sub btnUpdate_Click(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles btnUpdate.Click
> BindingContext(ds.Tables("dtOilLeases")).EndCurrentEdit()
> Dim strSQLServer As New SqlConnection(strConnString)
> strSQLServer.Open()
> Try
> Dim da As New SqlDataAdapter
> da.UpdateCommand = OilLeaseUpdate()
> da.UpdateCommand.UpdatedRowSource = UpdateRowSource.OutputParameters
> da.Update(ds, "dtOilLeases")
> Catch e_InsertException As System.Exception
> MsgBox(e_InsertException.Message)
> Throw e_InsertException
> Finally
> strSQLServer.Close()
> End Try
> End Sub
>
> Private Function OilLeaseUpdate() As SqlCommand
> Dim strSQLServer As New SqlConnection(strConnString)
> Dim cmd As New SqlCommand("OilLeaseUpdate", strSQLServer)
> cmd.CommandType = CommandType.StoredProcedure
> Dim pc As SqlParameterCollection = cmd.Parameters
> pc.Add(New System.Data.SqlClient.SqlParameter("@OilFieldID",
> System.Data.SqlDbType.Int, 4, "OilFieldID"))
> pc.Add(New System.Data.SqlClient.SqlParameter("@OilLeaseName",
> System.Data.SqlDbType.VarChar, 50, "OilLeaseName"))
> pc.Add(New System.Data.SqlClient.SqlParameter("@OilLeaseLocation",
> System.Data.SqlDbType.VarChar, 50, "OilLeaseLocation"))
> pc.Add(New System.Data.SqlClient.SqlParameter("@Original_OilLeaseID",
> System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, False,
> CType(0, Byte), CType(0, Byte), "OilLeaseID",
> System.Data.DataRowVersion.Original, Nothing))
> pc.Add(New System.Data.SqlClient.SqlParameter("@Original_Tstamp",
> System.Data.SqlDbType.VarBinary, 8, System.Data.ParameterDirection.Input,
> False, CType(0, Byte), CType(0, Byte), "Tstamp",
> System.Data.DataRowVersion.Original, Nothing))
> pc.Add(New System.Data.SqlClient.SqlParameter("@OilLeaseID",
> System.Data.SqlDbType.Int, 4, "OilLeaseID"))
> Return cmd
> End Function
>
> ************************************************
> ALTER PROCEDURE dbo.OilLeaseUpdate
> (
> @OilFieldID int,
> @OilLeaseName varchar(50),
> @OilLeaseLocation varchar(50),
> @Original_OilLeaseID int,
> @Original_Tstamp timestamp,
> @OilLeaseID int
> )
> AS
> SET NOCOUNT OFF;
> UPDATE OilLeases
> SET OilFieldID = @OilFieldID,
> OilLeaseName = @OilLeaseName,
> OilLeaseLocation = @OilLeaseLocation
> WHERE (OilLeaseID = @Original_OilLeaseID)
> AND (Tstamp = @Original_Tstamp OR @Original_Tstamp IS NULL AND Tstamp IS
> NULL);
> SELECT OilLeaseID, Tstamp, OilFieldID, OilLeaseName, OilLeaseLocation
> FROM OilLeases WHERE (OilLeaseID = @OilLeaseID)
>