Tuesday, March 20, 2012

Retrieving ID after INSERT Behind the scenes - Not using a grid view

Hi there. I looked through many other posts describing scope_identity but I am trying to achieve the same thing from the code behind. i.e. I need to some how call a method to execute the insert command and then return the ID so I can update other tables with this value.

I was going down the road of something like:

addnew as sqldatasource = new sqldatasource

addnew.insertcommand = "Insert into...; def @.NewID as scope_identity"

addnew.insert()

The problem is I don't know how to add a output parameter using VB or how to retrieve it.

Any help would be much appreciated, this is doing my head in...

Doug.

Hi, you can just new a SqlParameter and set the Direction to output like this:

Dim parameterdat2AsNew SqlParameter("@.accountnum", SqlDbType.NVarChar, 20, ParameterDirection.Output)

No comments:

Post a Comment