存储过程输出参数

xiaoxiao2021-03-01  4

代码调用方法:<br>SqlDatabase db = new SqlDatabase();<br> db.DbConn.Open();<br> db.DbCmd.CommandType = CommandType.StoredProcedure;<br> db.DbCmd.CommandText = "eip_ReportMt1";<br> db.DbCmd.Parameters.AddWithValue("@userId","1");<br> db.DbCmd.Parameters.AddWithValue("@Countstart",Convert.ToDateTime(txt1.Text));<br> db.DbCmd.Parameters.AddWithValue("@CountEnd", Convert.ToDateTime(txt2.Text));<br> SqlParameter sqlParam = new SqlParameter("@MtReportUser", SqlDbType.BigInt, 12);<br> sqlParam.Direction = ParameterDirection.Output;<br> db.DbCmd.Parameters.Add(sqlParam); <br> db.DbCmd.ExecuteNonQuery();<br> string a = sqlParam.Value.ToString();<br> txt3.Text = a.ToString();<br> db.DbConn.Close();<br>存储过程:<br>--前台个人报表按时间统计(查询某人某段时间的Mt数据)<br>CREATE PROCEDURE eip_ReportMt(--查询某人某段时间的Mt数据<br> @userId bigint, --输入:用户帐号<br> @Countstart datetime, --输入:开始时间<br> @CountEnd datetime, --输入:结束时间<br> @MtReportUser bigint OUTPUT<br>)<br>AS<br>declare @start bigint<br>DECLARE @end bigint<br><br>select @start=datediff(hh,'2007 - 07- 01 00:00:00',@Countstart)<br>select @end=datediff(hh,'2007 - 07- 01 00:00:00',@CountEnd)<br><br>BEGIN<br><br>select @MtReportUser=sum(MtSucceedNum) from eip_reportNote <br>where reportowner=@userId and StatTime<=@end and StatTime>=@start<br>END<br>return @MtReportUser<br>GO
转载请注明原文地址: https://www.6miu.com/read-4150257.html

最新回复(0)