我正在尝试SqlParameter
用字符串初始化 a 的值。但为什么它没有得到价值?
这是我尝试过的:
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;
}
}
存储过程:
alter procedure sp_Arsenic_getSourceStatusCount
@status varchar(10),
@count int
as
select @count=COUNT(status) from Arsenic_WaterSource where status=@status
return 1
插入断点我发现字符串变量status
的值是“安全的”,但在getsparameters[0].Value = (string) status;
行。如何解决这个问题?parameters[0].value
null