I delcare my sqlCommand sqlcmdInsNeAcc and connection from system.data.Sqlclient, I open my connection. all goes well then I do:
sqlcmdInsNeAcc.CommandText = "set nocount on insert into TblAccount(AccRisAsse,AccHldBll,Acctaxexm)
values(@AccRisAsse,@AccHldBll,@Acctaxexm) select id=scope_identity()"
pm = sqlcmdInsNeAcc.Parameters.Add(New SqlParameter("@AccountNumber", SqlDbType.BigInt))
pm.Direction = ParameterDirection.ReturnValue
Dim kAccountNumber as integer
kAccountNumber = sqlcmdInsNeAcc.Parameters("@AccountNumber").Value
pm = sqlcmdInsNeAcc.Parameters.Add(New SqlParameter("@AccRisAsse", SqlDbType.Bit))
pm.Value = myvalue1
pm = sqlcmdInsNeAcc.Parameters.Add(New SqlParameter("@AccHldBll", SqlDbType.Bit))
pm.Value = myvalue2
pm = sqlcmdInsNeAcc.Parameters.Add(New SqlParameter("@Acctaxexm", SqlDbType.Bit))
pm.Value = myvalue3
sqlcmdInsNeAcc.executenonquery
then when I try to display the value of my returned scope identity from the variable: kAccountNumber
ALL I GET IS ZERO although my row is created in the table with the right Account number: 100000056

I get scope_identity equal to 0
A.Russell
See the following thread for this topic:
http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=495662&SiteID=1
Please do not duplicate post.