问题很简单,当@docount为0时,“发生类型 int 的算术溢出错误,值 =2102021000151.000000
@docount为1时就一点问题也没有CREATE procedure CompanyTable_GetSearchResult
(@skey NVarChar(100),  
@pagesize int,  
@pageindex int,  
@docount bit)  
as  
set nocount on  
if(@docount=1)  
select count(id) from CompanyTable where coname like '%'+@skey+'%' and cointro is not null and 主营产品 <>'' and netaddress<>''
else
begin
declare @indextable table(id int identity(1,1),nid int)  
declare @PageLowerBound int  
declare @PageUpperBound int  
set @PageLowerBound=(@pageindex-1)*@pagesize  
set @PageUpperBound=@PageLowerBound+@pagesize  
set rowcount @PageUpperBound  
insert into @indextable(nid) select [id] from CompanyTable where coname like '%'+@skey+'%' and cointro is not null and 主营产品 <>'' and netaddress<>'' order by 诚信指数 desc  
select O.id,O.coName,O.cointro,O.主营产品,O.在线图片,O.NetAddress,O.网址图片,O.诚信值,O.诚信指数 
from CompanyTable O,@indextable t 
where O.id=t.nid  
and t.id>@PageLowerBound and t.id<=@PageUpperBound order by t.id
end  
set nocount off  
GO

解决方案 »

  1.   

    sql中int的最大值是2,147,483,647,当然超出范围了。用别的数据类型吧。
      

  2.   

    可能 nid int 定义的有问题
      

  3.   

    liaoxin009(小辛):int类型的数据位数没办法再增大了
      

  4.   

    值 =2102021000151.000000;
    应该是运算过程的一些中间表达式产生的值,
    我以前好像遇到过这样的问题:bigint=int+int,如果这两个int型数只和超过了int型的范围都会报错,要改成bigint=bigint+bigint才OK~
      

  5.   

    非常感谢:xbfitliu(阳光岁月) ,mailpq(偶是新手)也谢谢所有发言的网友问题解决了,我把int换成bigint就OK了
      

  6.   

    呵呵,说句实话看到sql server的存储过程就晕乎,加那么多@符号。如果网络允许还不如用dotnet自带的分页功能呢
      

  7.   

    现在我在查询分析器中调用可以显示正常的查询结果了,问题虽然解决了,但是在程序中调用却还是没有反应,
    在查询分析器中可以显示的数据在程序中却显示不到repeart中,这是怎么回事?程序中调用存储过程的代码:
    private void Page_Load(object sender, System.EventArgs e)
    {
    //页面初始化时进行数据绑定
    SqlConnection conn=new SqlConnection(Class.DataAccess.ConnectionStrBySql );
    if(!IsPostBack)
    {
    ViewState["QueryStr"] =Request["sf"]; cmd=new SqlCommand("CompanyTable_GetSearchResult",conn);
    cmd.CommandType=CommandType.StoredProcedure;
    cmd.Parameters.Add("@skey","+strsql+");
    cmd.Parameters.Add("@pagesize",1);
    cmd.Parameters.Add("@pageindex",1);
    cmd.Parameters.Add("@docount",true);
    conn.Open();
    pager.RecordCount=(int)cmd.ExecuteScalar();
    conn.Close();
    Bind();
    }
    }private void Bind()
    {
    string strsql = ViewState["QueryStr"] as string;

    SqlConnection conn=new SqlConnection(Class.DataAccess.ConnectionStrBySql );
    cmd=new SqlCommand("CompanyTable_GetSearchResult",conn);
    cmd.CommandType=CommandType.StoredProcedure;
    cmd.Parameters.Add("@skey","+strsql+");
    cmd.Parameters.Add("@pagesize",pager.PageSize);
    cmd.Parameters.Add("@pageindex",pager.CurrentPageIndex);
    cmd.Parameters.Add("@docount",false);
    conn.Open();
    RepeaterTem1.DataSource=cmd.ExecuteReader();
    RepeaterTem1.DataBind();
    conn.Close();
    }