我的逻辑层: /// <summary>
/// 统计情况
/// </summary>
/// <returns></returns>
public static SqlDataReader TongJi()
{
SqlParameter[] param = new SqlParameter[30]; param[0] = new SqlParameter("@AllowPreCount", 0);
param[1] = new SqlParameter("@AllPreArea", 0);
param[2] = new SqlParameter("@AllowPreZzCount", 0);
param[3] = new SqlParameter("@AllPreZzArea", 0);
param[4] = new SqlParameter("@AllowCount", 0);
param[5] = new SqlParameter("@AllArea", 0);
param[6] = new SqlParameter("@AllowZzCount", 0);
param[7] = new SqlParameter("@AllZzArea", 0);
param[8] = new SqlParameter("@PreCount", 0);
param[9] = new SqlParameter("@PreArea", 0);
param[10] = new SqlParameter("@PreZzCount", 0);
param[11] = new SqlParameter("@PreZzArea", 0);
param[12] = new SqlParameter("@TrueBuildCount", 0);
param[13] = new SqlParameter("@TrueArea", 0);
param[14] = new SqlParameter("@PreHouseRgCount", 0);
param[15] = new SqlParameter("@PreHouseRgArea", 0);
param[16] = new SqlParameter("@PreHouseRgZzCount", 0);
param[17] = new SqlParameter("@PreHouseRgZzArea", 0);
param[18] = new SqlParameter("@PreHouseCount", 0);
param[19] = new SqlParameter("@PreHouseArea", 0);
param[20] = new SqlParameter("@PreHouseZzCount", 0);
param[21] = new SqlParameter("@PreHouseZzArea", 0);
param[22] = new SqlParameter("@HouseRgCount", 0);
param[23] = new SqlParameter("@HouseRgArea", 0);
param[24] = new SqlParameter("@HouseRgZzCount", 0);
param[25] = new SqlParameter("@HouseRgZzArea", 0);
param[26] = new SqlParameter("@HouseCount", 0);
param[27] = new SqlParameter("@HouseArea", 0);
param[28] = new SqlParameter("@HouseZzCount", 0);
param[29] = new SqlParameter("@HouseZzArea", 0); return VisitBeiAn.RunDataReaderProceParam("WebStat", param);
}
我的数据访问层: public static SqlDataReader RunDataReaderProceParam(string strsql, SqlParameter[] param)
{
SqlConnection oconnection = new SqlConnection(connstr);
oconnection.Open();
SqlCommand ocommand = new SqlCommand(strsql);
ocommand.CommandType = CommandType.StoredProcedure;
ocommand.Connection = oconnection;
if (ocommand.Parameters.Count == 0)
{
foreach (SqlParameter p in param)
{
ocommand.Parameters.Add(p);
}
}
SqlDataReader sdr = ocommand.ExecuteReader();
return sdr;
}
我的存储过程:set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
goALTER procedure [dbo].[WebStat] @AllowPreCount int output ,@AllPreArea numeric(18,2) Output ,@AllowPreZzCount int Output ,@AllPreZzArea numeric(18,2) Output ,
@AllowCount int Output ,@AllArea numeric(18,2) Output ,@AllowZzCount int Output ,@AllZzArea numeric(18,2) Output ,
@PreCount int Output ,@PreArea numeric(18,2) Output ,@PreZzCount int Output ,@PreZzArea numeric(18,2) Output ,
@TrueBuildCount int Output ,@TrueArea numeric(18,2) Output ,
@PreHouseRgCount int Output , @PreHouseRgArea numeric(18,2) Output ,@PreHouseRgZzCount int Output , @PreHouseRgZzArea numeric(18,2) Output ,
@PreHouseCount int Output , @PreHouseArea numeric(18,2) Output ,@PreHouseZzCount int Output , @PreHouseZzArea numeric(18,2) Output ,
@HouseRgCount int Output , @HouseRgArea numeric(18,2) Output ,@HouseRgZzCount int Output , @HouseRgZzArea numeric(18,2) Output ,
@HouseCount int Output , @HouseArea numeric(18,2) Output ,@HouseZzCount int Output , @HouseZzArea numeric(18,2) Output asSELECT @AllowPreCount= COUNT(1) , @AllPreArea= SUM(YJZMJ)
FROM FWQK
WHERE (SFXYBA = '是') AND (ISNULL(cdid, 0) = 0)
下略应该是没有过错的啊,老是提示没有输入参加,我都要疯了,请大家帮忙。谢谢
/// 统计情况
/// </summary>
/// <returns></returns>
public static SqlDataReader TongJi()
{
SqlParameter[] param = new SqlParameter[30]; param[0] = new SqlParameter("@AllowPreCount", 0);
param[1] = new SqlParameter("@AllPreArea", 0);
param[2] = new SqlParameter("@AllowPreZzCount", 0);
param[3] = new SqlParameter("@AllPreZzArea", 0);
param[4] = new SqlParameter("@AllowCount", 0);
param[5] = new SqlParameter("@AllArea", 0);
param[6] = new SqlParameter("@AllowZzCount", 0);
param[7] = new SqlParameter("@AllZzArea", 0);
param[8] = new SqlParameter("@PreCount", 0);
param[9] = new SqlParameter("@PreArea", 0);
param[10] = new SqlParameter("@PreZzCount", 0);
param[11] = new SqlParameter("@PreZzArea", 0);
param[12] = new SqlParameter("@TrueBuildCount", 0);
param[13] = new SqlParameter("@TrueArea", 0);
param[14] = new SqlParameter("@PreHouseRgCount", 0);
param[15] = new SqlParameter("@PreHouseRgArea", 0);
param[16] = new SqlParameter("@PreHouseRgZzCount", 0);
param[17] = new SqlParameter("@PreHouseRgZzArea", 0);
param[18] = new SqlParameter("@PreHouseCount", 0);
param[19] = new SqlParameter("@PreHouseArea", 0);
param[20] = new SqlParameter("@PreHouseZzCount", 0);
param[21] = new SqlParameter("@PreHouseZzArea", 0);
param[22] = new SqlParameter("@HouseRgCount", 0);
param[23] = new SqlParameter("@HouseRgArea", 0);
param[24] = new SqlParameter("@HouseRgZzCount", 0);
param[25] = new SqlParameter("@HouseRgZzArea", 0);
param[26] = new SqlParameter("@HouseCount", 0);
param[27] = new SqlParameter("@HouseArea", 0);
param[28] = new SqlParameter("@HouseZzCount", 0);
param[29] = new SqlParameter("@HouseZzArea", 0); return VisitBeiAn.RunDataReaderProceParam("WebStat", param);
}
我的数据访问层: public static SqlDataReader RunDataReaderProceParam(string strsql, SqlParameter[] param)
{
SqlConnection oconnection = new SqlConnection(connstr);
oconnection.Open();
SqlCommand ocommand = new SqlCommand(strsql);
ocommand.CommandType = CommandType.StoredProcedure;
ocommand.Connection = oconnection;
if (ocommand.Parameters.Count == 0)
{
foreach (SqlParameter p in param)
{
ocommand.Parameters.Add(p);
}
}
SqlDataReader sdr = ocommand.ExecuteReader();
return sdr;
}
我的存储过程:set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
goALTER procedure [dbo].[WebStat] @AllowPreCount int output ,@AllPreArea numeric(18,2) Output ,@AllowPreZzCount int Output ,@AllPreZzArea numeric(18,2) Output ,
@AllowCount int Output ,@AllArea numeric(18,2) Output ,@AllowZzCount int Output ,@AllZzArea numeric(18,2) Output ,
@PreCount int Output ,@PreArea numeric(18,2) Output ,@PreZzCount int Output ,@PreZzArea numeric(18,2) Output ,
@TrueBuildCount int Output ,@TrueArea numeric(18,2) Output ,
@PreHouseRgCount int Output , @PreHouseRgArea numeric(18,2) Output ,@PreHouseRgZzCount int Output , @PreHouseRgZzArea numeric(18,2) Output ,
@PreHouseCount int Output , @PreHouseArea numeric(18,2) Output ,@PreHouseZzCount int Output , @PreHouseZzArea numeric(18,2) Output ,
@HouseRgCount int Output , @HouseRgArea numeric(18,2) Output ,@HouseRgZzCount int Output , @HouseRgZzArea numeric(18,2) Output ,
@HouseCount int Output , @HouseArea numeric(18,2) Output ,@HouseZzCount int Output , @HouseZzArea numeric(18,2) Output asSELECT @AllowPreCount= COUNT(1) , @AllPreArea= SUM(YJZMJ)
FROM FWQK
WHERE (SFXYBA = '是') AND (ISNULL(cdid, 0) = 0)
下略应该是没有过错的啊,老是提示没有输入参加,我都要疯了,请大家帮忙。谢谢
所以你的参数类型也应该对应 System.Data.ParameterDirection.Output比如:
param[0] = new SqlParameter("@AllowPreCount", 0);
param[0].Direction= System.Data.ParameterDirection.Output;如果要传递数据库中的 null 进去,则是
param[0].Value =System.DBNull.Value;
真正体现面向对象
sorry!