| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 606 人关注过本帖
标题:下面是存储过程哪里错误了呢
只看楼主 加入收藏
liaohongchu
Rank: 1
等 级:新手上路
帖 子:133
专家分:0
注 册:2008-4-25
结帖率:78.72%
收藏
已结贴  问题点数:20 回复次数:2 
下面是存储过程哪里错误了呢
调用存储过程
public int SelectCount(string strWhere)
  {
  int theValue;
  using (SqlConnection myConnection = new SqlConnection(UserCenterConfiguration.Default.DbConnectionString))
  {

  using (SqlCommand command = new SqlCommand("usp_Get_BlogAttentionCount", myConnection))
  {
   = CommandType.StoredProcedure;
  command.Parameters.Add("@count", SqlDbType.Int);
  command.Parameters.Add("@strWhere", SqlDbType.NVarChar, 500, strWhere);
  command.Parameters["@count"].Direction = ParameterDirection.Output;
  try
  {
  command.ExecuteNonQuery();
  theValue = (int)command.Parameters["@count"].Value;
  myConnection.Close();
  }
  catch
  {
  myConnection.Close();
  theValue = 0;
  }
  return theValue;
  }
  }
  }


下面是存储过程
ALTER procedure [dbo].[usp_Get_BlogAttentionCount]
(
@strWhere nvarchar(500)='',
@count int output
)
as
declare @sqlStr nvarchar(1000)
if @strWhere != ''
  set @sqlStr = N'select @COUNT = count(id) from BlogAttention where 1=1 ' + @strWhere  
else
  set @sqlStr = N'select @COUNT = count(id) from BlogAttention'

exec sp_executesql @sqlStr,N'@count int output',@count output
搜索更多相关主题的帖子: command public count 
2010-09-13 14:49
qingshuiliu
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:17
帖 子:323
专家分:1538
注 册:2009-12-28
收藏
得分:20 
搞的有些复杂了
可能的错误地方,作为你的参考:
if @strWhere != '' ==》if len(@strWhere)>0 好一点
“exec sp_executesql @sqlStr,N'@count int output',@count output ” 这句不需要。
上面的set语句已经给@count赋值了。

2010-09-13 16:48
liaohongchu
Rank: 1
等 级:新手上路
帖 子:133
专家分:0
注 册:2008-4-25
收藏
得分:0 
谢谢 你找到原因了 没有这个打开myConnection.open();

command.ExecuteNonQuery();
  theValue = (int)command.Parameters["@count"].Value;
  myConnection.Close();
2010-09-14 08:15
快速回复:下面是存储过程哪里错误了呢
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011644 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved