Abe Miessler
Abe Miessler

Reputation: 85056

Is it possible to get the Identity value in the ItemInserted event in a listView?

I'd rather not make a call to the database to query @@IDENTITY. Is there some way to get the identity value for what was just inserted through code?

Upvotes: 0

Views: 1621

Answers (2)

Manu
Manu

Reputation: 29143

Try using SCOPE_IDENTITY() instead.

Upvotes: 0

Abe Miessler
Abe Miessler

Reputation: 85056

Found a solution by adding an OnInserted event to my LinqDataSource that my listview was using. See below:

protected void lds_Personnel_OnInserted(object sender, LinqDataSourceStatusEventArgs e)
{
    int id= ((Personnel)e.Result).IdentityNameHere;
.
.
.
}

Hope it's helpful to someone.

Upvotes: 1

Related Questions