Saturday, March 26, 2011

How to catch return value by using Asp.net and Stored procedure(sqlserver)?



Create procedure CheckEmpId
(
@EmpId_sp varchar(10)
)
as
begin
declare @count int
select @count=count(EmpId_db) from dbo.EmployeeMaster where EmpId_db=@EmpId_sp
return @count
end

#region To display Customer names
        public Boolean getCusNo()
        {
            try
            {
                sqlcmd = new SqlCommand("getCusName_sp", sqlcon);
                sqlcmd.CommandType = CommandType.StoredProcedure;
                sqlcmd.Parameters.Add("@CusNo_sp", SqlDbType.VarChar).Value = cusNo_cl;
                sqlcmd.Parameters.Add("return_value", SqlDbType.Int).Direction=ParameterDirection.ReturnValue;
                sqlcon.Open();
                sqlcmd.ExecuteNonQuery();
                int i = Convert.ToInt32(sqlcmd.Parameters["return_value"].Value);
                if (i == 1)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                sqlcon.Close();
            }

        }

1 comment: