ALTER PROCEDURE [dbo].[InsertmployeeAndGetScope] -- Add the parameters for the stored procedure here @LastName nvarchar(20)=null, @FirstName nvarchar(10), @EmplyeeId int= null output AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; -- Insert statements for procedure here insert into dbo.Employees(LastName,FirstName) values(@LastName,@FirstName); set @EmplyeeId=SCOPE_IDENTITY(); return @EmplyeeId; END
public int insertemployeeandgetid() { string connStr = ConfigurationManager.ConnectionStrings["north"].ToString(); SqlConnection conn = new SqlConnection(connStr); conn.Open(); SqlCommand dCmd = new SqlCommand("InsertmployeeAndGetScope", conn); dCmd.CommandType = CommandType.StoredProcedure; try { dCmd.Parameters.AddWithValue("@LastName", "zarif"); dCmd.Parameters.AddWithValue("@FirstName", "mhamad"); dCmd.Parameters.AddWithValue("@EmplyeeId", null); return Convert.ToInt32(dCmd.ExecuteScalar()); } catch { throw; } finally { dCmd.Dispose(); conn.Close(); conn.Dispose(); } }
SqlParameter p = cmd.Parameters.Add("@MyParam", SqlDbType.Int); p.Direction = ParameterDirection.Output;
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)