Calling stored procedure using c# by passing parameter that is declared inside the repository method

272 Views Asked by At

Here am Passing employeename as parameter but declared inside the method instead of at the method call and then added as a parameter to the stored procedure. But the result i get here includes all the employeename data. What am I trying to achieve here is to get data for John from GetEmployee method, instead am getting data for all employeenames in the view. Any ideas where am doing wrong?

public IList<EmployeeModel> GetEmployee()
    {         
        string employeeName= "John";
            List<EmployeeModel> empdata;
            using (DbCommand cmd = this.UoW.CreateCommand())
            {
                cmd.CommandText = "getemployee";
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.AddParameter("employeeName", DbType.String, ParameterDirection.Input, employeeName);
                cmd.AddParameter("outputcur", Oracle.ManagedDataAccess.Client.OracleDbType.RefCursor, ParameterDirection.Output, string.Empty);
                empdata= cmd.ExecuteQuery<EmployeeModel>();
            }
            return empdata;              
    }

}

Here's the code in procedure

PROCEDURE getemployee(employeeName VARCHAR, outputcur OUT SYS_REFCURSOR ) IS
   BEGIN
    OPEN outputcur FOR SELECT
                          *
                     FROM
                         V_EMPLOYEE
                     WHERE
                         empname= employeeName; //John is the employeename

END;

And here in this method which is different from above, am passing parameter while calling it,and it works

public IList<AllEmployeeModel> GetAllEmployees(string employeeId)
    {

            List<AllEmployeeModel> allempdata= new List<AllEmployeeModel>();

            using (DbCommand cmd = this.UoW.CreateCommand())
            {
                cmd.CommandText = "getallemployees";
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.AddParameter("employeeId", DbType.String, ParameterDirection.Input,employeeId);

             cmd.AddParameter("output",Oracle.ManagedDataAccess.Client.OracleDbType.RefCursor,ParameterDirection.Output, string.Empty);

                allempdata= cmd.ExecuteQuery<AllEmployeeModel>();
            }
            return allempdata;

    }
0

There are 0 best solutions below