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..

Recommended Answers

All 2 Replies

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.

commented: Correct. +7

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.