求助,使用GetDataReader调用存储过程不能获得out参数值,out参数value值为null 返回
SqlSugar
老数据
3
2499
悬赏:5 飞吻
List<string> qknamelist = new List<string>();
Dictionary<string, string> dict = new Dictionary<string, string>();
var inputclassname = new SugarParameter("@classname", classname);
var outquekao = new SugarParameter("@quekao", null, true);
var outavgdb = new SugarParameter("@avgdb", null, true);
var outavgcsharap = new SugarParameter("@avgcsharp", null, true);
var outcankao = new SugarParameter("@cankao", null, true);
var d=Db.Ado.UseStoredProcedure().GetDataReader("usp_scorequery", inputclassname, outquekao, outavgdb, outavgcsharap, outcankao);
SqlDataReader dr = d as SqlDataReader;
if (dr.HasRows)
{
while (dr.Read())
{
qknamelist.Add(dr.GetString(0));
}
}
dict["quekao"] = outquekao.Value.ToString();
dict["cankao"] = outcankao.Value.ToString();
dict["outavgdb"] = outavgdb.Value.ToString();
dict["outavgcsharap"] = outavgcsharap.Value.ToString();
canshu = dict;
return qknamelist;ALTER proc usp_scorequery @classname nvarchar(20), @quekao int output, @cankao int output, @avgdb int output, @avgcsharp int output as --算出缺考的人数 IF (LEN(@classname)=0) BEGIN --按全部人员计算 --缺考的人数 select @quekao=count(*) from Students INNER join StudentClass on StudentClass.ClassId=Students.ClassId where students.StudentId not in (select scorelist.StudentId from scorelist) --参考人数和各科平均成绩 select @cankao=count(*),@avgdb=AVG(SQLServerDB),@avgcsharp=AVG(CSharp) from ScoreList --缺考学生的名字 select StudentName as 缺考学生姓名 from Students where StudentId not in (select StudentId from ScoreList) END ELSE BEGIN--根据班级名称计算 --查询缺考人数 select @quekao=count(*) from Students INNER join StudentClass on StudentClass.ClassId=Students.ClassId where students.StudentId not in (select scorelist.StudentId from scorelist) and ClassName=@classname --参考人数和各科平均成绩 select @cankao=count(*),@avgdb=AVG(SQLServerDB),@avgcsharp=avg(CSharp) from ScoreList INNER join Students on students.StudentId=ScoreList.StudentId inner join StudentClass on StudentClass.ClassId=Students.ClassId where ClassName=@classname --查询缺考的学生名称 select StudentName as 缺考的学生名称 from Students INNER join StudentClass on StudentClass.ClassId=Students.ClassId where Students.StudentId not in (select ScoreList.StudentId from ScoreList) and ClassName=@classname END
热忱回答(3)
-
fate stay night VIP0
2019/1/21验证下存储过程进逻辑了吗
0 回复 -
fate stay night VIP0
2019/1/21ALTERproc usp_scorequery@classname nvarchar(20),@quekaointoutput,@cankaointoutput,@avgdbintoutput,@avgcsharpintoutputasbegin
set @avgcsharp=1
end
这样测一下看看
0 回复 -
yunle VIP0
2019/1/21
存储过程代码在sqlserver ssms里测试过,可以正常运行,上面的c#代码中将调用存储过程的GetDataReader换成GetDataTable后,可以获得OUT参数value值
0 回复