Click here to Skip to main content
15,901,426 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
here is stored procedure code :
ALTER procedure [dbo].[LtoffrEmpPst]
@offPst nvarchar(60),
@sec nvarchar(60) output,
@vil nvarchar(60) output,
@cntr nvarchar(60) output,
@dat datetime output
as
begin
SET NOCOUNT ON;
select @sec=us.Nm_societ,@vil=vil.Nom_ville,@cntr=cn.typContra,@dat=emp.Dat_creat
from OffrEmplwa emp,typ_Uzrs us,sectr_Activit sec,fonkcion fnk ,Vlle vil,Expriens ex
,TypContra cn,Rolle rl where emp.Id_Uzr=us.Id_user and emp.Id_veil=vil.Id_vll
and emp.Id_Contra=cn.IdContra and us.Id_roole=rl.Id_rol
and us.Id_roole=1 and emp.NmPost like '%@offPst%'
group by emp.Id_OffrEmp,us.Nm_societ,emp.NmPost,vil.Nom_ville
,cn.typContra,emp.Dat_creat
end

here is the code of DAL.cs

public DataTable offemplistBypst(DTO dUser)
{
DataTable dt = null;
using (SqlConnection cnx = Conection.GetDbConnection())
{
using (SqlCommand cmd = new SqlCommand("LtoffrEmpPst", cnx))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@offPst", SqlDbType.NVarChar,60).Value = dUser.NmPst;
cnx.Open();
cmd.ExecuteNonQuery();
dt = new DataTable();
SqlDataReader dr = cmd.ExecuteReader();
dt.Load(dr);
dr.Close();
dr.Dispose();
return dt;
}
}
}
plz, can anybody tell me how to make this work
Posted

Since they are output parameters you need to add them to the cmd.Parameters collection. For example, see here http://stackoverflow.com/questions/12174399/accessing-sql-server-stored-procedure-output-parameter-in-c-sharp[^]

Alternatively, and preferably in my opinion, you don't use output parameters but instead just run a normal Select statement and then you can access the fields that are selected by using dr["fieldName"]
 
Share this answer
 
Try following code:

C#
public DataTable offemplistBypst(DTO dUser)
{
DataTable dt = null;
using (SqlConnection cnx = Conection.GetDbConnection())
{
using (SqlCommand cmd = new SqlCommand("LtoffrEmpPst", cnx))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@offPst", SqlDbType.NVarChar,60).Value = dUser.NmPst;
SqlParameter parm2 = new SqlParameter("@sec", SqlDbType.VarChar);
    parm2.Size = 60;
    parm2.Direction = ParameterDirection.Output; 
    cmd.Parameters.Add(parm2);
SqlParameter parm3 = new SqlParameter("@vil", SqlDbType.VarChar);
    parm2.Size = 60;
    parm2.Direction = ParameterDirection.Output; 
    cmd.Parameters.Add(parm3);
SqlParameter parm4 = new SqlParameter("@cntr", SqlDbType.VarChar);
    parm2.Size = 60;
    parm2.Direction = ParameterDirection.Output; 
    cmd.Parameters.Add(parm4);
SqlParameter parm5 = new SqlParameter("@dat", SqlDbType.DateTime);
    parm2.Size = 60;
    parm2.Direction = ParameterDirection.Output; 
    cmd.Parameters.Add(parm5);

cnx.Open();
cmd.ExecuteNonQuery();
dt = new DataTable();
SqlDataReader dr = cmd.ExecuteReader();
dt.Load(dr);
dr.Close();
dr.Dispose();
return dt;
}
}
}
 
Share this answer
 
You can use cmd.Parameter.AddWithValue("@your_param",value) method instead.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900