I am trying to initialize the value of a SqlParameter
with a string. but why does it not get the value ?
This is what I tried:
int loadChart(string status)
{
connect();
SqlParameter[] parameters ={
new SqlParameter("status", SqlDbType.VarChar, 10),
new SqlParameter("count", SqlDbType.Int, 4)
};
parameters[0].Value = status;
parameters[1].Direction = ParameterDirection.Output;
SqlCommand cmd = new SqlCommand("sp_Arsenic_getSourceStatusCount", objConnection);
foreach (SqlParameter param in parameters)
{
cmd.Parameters.Add(param);
}
cmd.ExecuteNonQuery();
disConnect();
int count;
count =(int) parameters[1].Value;
return count;
}
}
The stored procedure:
alter procedure sp_Arsenic_getSourceStatusCount
@status varchar(10),
@count int
as
select @count=COUNT(status) from Arsenic_WaterSource where status=@status
return 1
Inserting a breakpoint I have discovered that the string variable status
gets its value "safe" but at parameters[0].Value = (string) status;
line parameters[0].value
gets null
. How to resolve this issue ?