Getting Identity Key during an Insert w/FormView

Posts   
 
    
joeliir
User
Posts: 8
Joined: 25-Jul-2006
# Posted on: 25-Aug-2006 16:15:40   

I am using the Self Servicing model in c# and using the FormView along with the LLBLGenProDataSource. When doing an Insert using the FormView, how do i get the key value (an automatic increasing identity integer) after the insert? I was looking through the PerformWorkEventArgs but didn't see anything that lead me to my answer. Any replies would be great!

Thanks!

Joel

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 25-Aug-2006 16:24:59   

You may have the Key field be mapped to an invisible grid column, and then when you see the new row inserted on the grid, you may check this column's value. Also you may use the Refetch property of the LLBLGenProDataSourceControl to To ensure fresh data from the database is retrieved.

joeliir
User
Posts: 8
Joined: 25-Jul-2006
# Posted on: 25-Aug-2006 16:40:29   

Ok so there is no easy way to do this using just the FormView and LLBLGenProDataSource? The issue with they way you mentioned is that multiple people could be adding at the same time. Should i just do this using code instead of the LLBLGenProDataSource?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 25-Aug-2006 16:47:07   

joeliir wrote:

Ok so there is no easy way to do this using just the FormView and LLBLGenProDataSource? The issue with they way you mentioned is that multiple people could be adding at the same time. Should i just do this using code instead of the LLBLGenProDataSource?

That's not possible: the webform is for a single session, so you won't have the situation where multiple people are adding data to the same collection in a single datasourcecontrol.

The FormView calls ExecuteInsert or ExecuteUpdate on the datasourcecontrol, which then performs the action (either by itself or by raising PerformWork event) which then makes the control changed and the grid will refetch itself. If you really want the ID, you could also set LivePersistence to false and bind to PerformWork in the code behind, in which you will obtain the unitofwork object which contains the entity to save.

Frans Bouma | Lead developer LLBLGen Pro