954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

how can i get the last ID that i inserted in database

using this code.stored procedure

@_Empno nvarchar(8),@_Surname nvarchar(50),
@_Firstname nvarchar(50),
@_Middlenamenvarchar(50),@_PermanentAdd nvarchar(Max),
@_PresentAdd nvarchar(Max),
@_Identity ouput int

AS

SET NOCOUNT ON;
INSERT INTO TblEmpPersonal
(
Empno,
Surname,
Firstname,
Middlename,
PermanentAdd)

values(INSERT INTO TblEmpPersonal
(
@_Empno,
@_Surname,
@_Firstname,
@_Middlename,
@_PermanentAdd)

set @_Identity = (Select cast(scope_identity() as int) as empID)


here my DAL

public static bool Create(IEmployee Emp)
{
SqlParameter[] _parameters = {
new SqlParameter("@_Empno", Emp.Empno),
new SqlParameter("@_Surname",Emp.Surname),
new SqlParameter("@_Firstname", Emp.Firstname),
new SqlParameter("@_Middlename",Emp.Middlename),
new SqlParameter("@_PermanentAdd",Emp.PermanentAdd),
new SqlParameter("@_PresentAdd",Emp.PresentAdd),
new SqlParameter("@_Identity",Emp.Identity)};
return Convert.ToBoolean(connectionString,CommandType.Stor edProcedure,"_Insert_Employee",_parameters));
}

pls help me..
thanx in advance..

ndhamecha
Newbie Poster
4 posts since Feb 2010
Reputation Points: 6
Solved Threads: 0
 

I haven't used C in years, but if I remember correctly you need to use

@@IDENTITY


to retrieve the Last ID.

Anyone more familiar, correct me if I'm wrong.

Banderson
Junior Poster in Training
66 posts since Aug 2004
Reputation Points: 17
Solved Threads: 8
 

Yes, that is it just do a Select @var = @@IDENTITY

MattBerry
Newbie Poster
12 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You