Retrieve Identity Column via Insert Parameter

Joined
Nov 14, 2006
Messages
2
Reaction score
0
Hello, I am adding a record into SQL server via VB asp.net.
I want to retrieve the ID of the record just added.
Below is what i have thus far.
It runs, but I cannot figure out how to read or in fact get the ID.

Do note, I did not include all the the insert parameter call outs.

please help



SqlDataSource1.InsertParameters.Add("getID", TypeCode.Int16, 0)
SqlDataSource1.InsertParameters.Item("getID").Direction = ParameterDirection.InputOutput

SqlDataSource1.InsertCommand = "Insert into tblcustomer (txtname,txtaddress1,txtaddress2,txtcity,txtstate,areacode,txtphone,ext,txtzip,txtfax,txtcountry,intjde,intregion,deactivated) Values (@txtname,@txtaddress1,@txtaddress2,@txtcity,@txtstate,@areacode,@txtphone,@ext,@txtzip,@txtfax,@txtcountry,@intjde,@intregion,@deactivated);Set @getID = Scope_Identity();"
SqlDataSource1.Insert()

Response.Write("Test " & SqlDataSource1.InsertParameters.Item(14).DefaultValue.ToString)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top