![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
![]() |

|
| Programming tutorials All Knowledge Info and links to posted here |
![]() |
|
How to use SCOPE_IDENTITY() in ASP.NET
|
LinkBack | Thread Tools | Display Modes |
|
|
#1 (permalink) |
|
Administrator
Posts: 876
Join Date: Oct 2005
Rep Power: 10
IM:
|
Dim objConnection As SqlConnection Dim objCommand As SqlCommand Dim strConnection, strSQL As String Dim newUserID As String ' Database Connection strConnection = "server=LOCAL;uid=sa;password=;database=sample_dat abase" ' Our SQL String that will insert a new record to database table strSQL = "Insert into member_list ( " strSQL + = "userName ,passWord" strSQL + = ")" strSQL + = " values (" strSQL + = "@uName,@pName" strSQL + = ")" ' Here this part of SQL code will take the latest identity strSQL + = "; SELECT SCOPE_IDENTITY() ; " objConnection = New SqlConnection(strConnection) objCommand = New SqlCommand(strSQL, objConnection) objCommand.Parameters.Add("@uName", SqlDbType.NVarChar).Value = "some text here or a variable" objCommand.Parameters.Add("@pWord", SqlDbType.NVarChar).Value = "some text here or a variable" objCommand.Connection.Open() newUserID = objCommand.ExecuteScalar objCommand.Connection.Close() SCOPE_IDENTITY takes only latest records identity only in current scope, but if you use @@IDENTITY will retrurn identity in all scopes. |
|
|
|
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|