RecordID not set after insert object

RecordID not set after insert object

Old forum URL: forums.lhotka.net/forums/t/6529.aspx


BuckeyeJeff posted on Friday, February 27, 2009

I have a webpage that is used for inserting data.  User saves and the objects are build and then .added into the clsa business list base.  I then call save on that business list base and it calls data layer and insert into database.  Each insert returns the new records id and assign it to record id property.  once back to webpage, i want to grab the new id's for just inserted records and use for something else. but they all say 0

 

I am doing

objects.add(new object)

objects.add(new object)

objects.add(new object).......

objects.save()

for each item as object in objects

response.write(item.NewRecordID) 'it comes back as 0, rather than the new id

next

JohnB replied on Friday, February 27, 2009

Are you capturing the new id when your "object" is being inserted?

Dim p0 As New SqlParameter("@NewRecordID", SqlDbType.Int)
p0.Direction = ParameterDirection.Output
cmd.Parameters.Add(p0)

DoInsertUpdate(cmd)

'-- Retrieve the new id from the stored procedure
_newRecordID = DirectCast(cmd.Parameters("@NewRecordID").Value, Int32)

Hope this helps,
John

tmg4340 replied on Friday, February 27, 2009

You don't say which version of the framework you're using, but the first thing I'd try is to change "objects.Save()" to "objects = objects.Save()".  In general, "objects.Save()" is always incorrect code in CSLA.  Remember that the DP_ routines return an updated copy of the object - they don't update the object in-place.

HTH

- Scott

BuckeyeJeff replied on Friday, February 27, 2009

I am doing

m_LineItems = New LineItems

 

loop

LineItem item = new lineitem

...update values

m_LineItems.add(item)

end loop

m_lineitems.save()

investigate LineItemId for each item so as to do whatever

JoeFallon1 replied on Friday, February 27, 2009

As Scott stated earlier the bug is in your code.

m_lineitems.save()  is wrong.

It needs to be:

m_lineitems = m_lineitems.save()

Joe

 

bignick replied on Tuesday, March 17, 2009

So how would you access the new instance returned when you are using the CslaActionExtender control in win forms?

Mordy replied on Friday, September 11, 2009

"DP_ routines return an updated copy of the object - they don't update the object in-place."

Thanks Bignick - I'd been staring at a similar problem and just not seeing the woods for the trees!

Copyright (c) Marimer LLC