| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1542 人关注过本帖
标题:为什么后台有值,前台却没有显示
只看楼主 加入收藏
koleal
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2008-7-2
收藏
 问题点数:0 回复次数:8 
为什么后台有值,前台却没有显示
下面的这个存储过程在存储过程编写的页面里执行时有数据返回,可是在前后进行绑定后就不行了,没有数据显示出来,前台是用objectdatasource绑定的,
谁能帮帮忙

------------------------------------------------------------
--
--通用的分页存储过程
--
-------------------------------------------------------------
ALTER PROCEDURE dbo.PageList
(
@tblName     nvarchar(200),        ----要显示的表或多个表的连接
@fldName     nvarchar(500) = '*',    ----要显示的字段列表
@pageSize    int = 1,        ----每页显示的记录个数
@page        int = 10,        ----要显示那一页的记录
@fldSort    nvarchar(200) = null,    ----排序字段列表或条件
@Sort        bit = 0,        ----排序方法,0为升序,1为降序(如果是多字段排列Sort指代最后一个排序字段的排列顺序(最后一个排序字段不加排序标记)--程序传参如:' SortA Asc,SortB Desc,SortC ')
@strCondition    nvarchar(1000) = null,    ----查询条件,不需where,以And开始
@ID        nvarchar(150),        ----主表的主键
@Dist                 bit = 0 ,          ----是否添加查询字段的 DISTINCT 默认0不添加/1添加
@pageCount    int = 1 output,            ----查询结果分页后的总页数
@Counts    int = 1 output,                ----查询到的记录数
@strSql          nvarchar(1000) = '' output  -----最后返回的SQL语句
)
AS
SET NOCOUNT OFF
Declare @sqlTmp nvarchar(1000)        ----存放动态生成的SQL语句
Declare @strTmp nvarchar(1000)        ----存放取得查询结果总数的查询语句
Declare @strID     nvarchar(1000)        ----存放取得查询开头或结尾ID的查询语句
Declare @strSortType nvarchar(10)    ----数据排序规则A
Declare @strFSortType nvarchar(10)    ----数据排序规则B
Declare @SqlSelect nvarchar(50)         ----对含有DISTINCT的查询进行SQL构造
Declare @SqlCounts nvarchar(50)          ----对含有DISTINCT的总数查询进行SQL构造
if @Dist  = 0
begin
    set @SqlSelect = 'select '
    set @SqlCounts = 'Count(*)'
end

if @Sort=0
begin
    set @strFSortType=' ASC '
    set @strSortType=' DESC '
end
else
begin
    set @strFSortType=' DESC '
    set @strSortType=' ASC '
end
--------生成查询语句--------
--此处@strTmp为取得查询结果数量的语句
if @strCondition is null or @strCondition=''     --没有设置显示条件
begin
    set @sqlTmp =  @fldName + ' From ' + @tblName
    set @strTmp = @SqlSelect+' @Counts='+@SqlCounts+' FROM '+@tblName
    set @strID = ' From ' + @tblName
end
else
begin
    set @sqlTmp = + @fldName + 'From ' + @tblName + ' where (1>0) ' + @strCondition
    set @strTmp = @SqlSelect+' @Counts='+@SqlCounts+' FROM '+@tblName + ' where (1>0) ' + @strCondition
    set @strID = ' From ' + @tblName + ' where (1>0) ' + @strCondition
end
----取得查询结果总数量-----
exec sp_executesql @strTmp,N'@Counts int out ',@Counts out
declare @tmpCounts int
if @Counts = 0
    set @tmpCounts = 1
else
    set @tmpCounts = @Counts
    --取得分页总数
    set @pageCount=(@tmpCounts+@pageSize-1)/@pageSize
    /**//**当前页大于总页数 取最后一页**/
    if @page>@pageCount
        set @page=@pageCount
    --/*-----数据分页2分处理-------*/
    declare @pageIndex int --总数/页大小
    declare @lastcount int --总数%页大小
    set @pageIndex = @tmpCounts/@pageSize
    set @lastcount = @tmpCounts%@pageSize
    if @lastcount > 0
        set @pageIndex = @pageIndex + 1
    else
        set @lastcount = @pagesize
    --//***显示分页
    if @strCondition is null or @strCondition=''     --没有设置显示条件
    begin
        if @pageIndex<2 or @page<=@pageIndex / 2 + @pageIndex % 2   --前半部分数据处理
            begin
                set @strTmp=@SqlSelect+' top '+ CAST(@pageSize as VARCHAR(4))+' '+ @fldName+' from '+@tblName
                        +' where '+@ID+' not in('+ @SqlSelect+' top '+ CAST(@pageSize*(@page-1) as Varchar(20)) +' '+ @ID +' from '+@tblName
                        +' order by '+ @fldSort +' '+ @strFSortType+')'
                        +' order by '+ @fldSort +' '+ @strFSortType
            end
        else
            begin
            set @page = @pageIndex-@page+1 --后半部分数据处理
                if @page <= 1 --最后一页数据显示
                    set @strTmp=@SqlSelect+' * from ('+@SqlSelect+' top '+ CAST(@lastcount as VARCHAR(4))+' '+ @fldName+' from '+@tblName
                        +' order by '+ @fldSort +' '+ @strSortType+') AS TempTB'+' order by '+ @fldSort +' '+ @strFSortType
                else               
                    set @strTmp=@SqlSelect+' * from ('+@SqlSelect+' top '+ CAST(@pageSize as VARCHAR(4))+' '+ @fldName+' from '+@tblName
                        +' where '+@ID+' not in('+ @SqlSelect+' top '+ CAST(@pageSize*(@page-2)+@lastcount as Varchar(20)) +' '+ @ID +' from '+@tblName
                        +' order by '+ @fldSort +' '+ @strSortType+')'
                        +' order by '+ @fldSort +' '+ @strSortType+') AS TempTB'+' order by '+ @fldSort +' '+ @strFSortType
            end
    end
    else --有查询条件
    begin
        if @pageIndex<2 or @page<=@pageIndex / 2 + @pageIndex % 2   --前半部分数据处理
        begin
                set @strTmp=@SqlSelect+' top '+ CAST(@pageSize as VARCHAR(4))+' '+ @fldName +' from  '+@tblName
                    +' where '+@ID+' not in('+ @SqlSelect+' top '+ CAST(@pageSize*(@page-1) as Varchar(20)) +' '+ @ID +' from '+@tblName
                    +' Where (1>0) ' + @strCondition + ' order by '+ @fldSort +' '+ @strFSortType+')'
                    +' ' + @strCondition + ' order by '+ @fldSort +' '+ @strFSortType                 
        end
        else
        begin
            set @page = @pageIndex-@page+1 --后半部分数据处理
            if @page <= 1 --最后一页数据显示
                    set @strTmp=@SqlSelect+' * from ('+@SqlSelect+' top '+ CAST(@lastcount as VARCHAR(4))+' '+ @fldName+' from '+@tblName
                        +' where (1>0) '+ @strCondition +' order by '+ @fldSort +' '+ @strSortType+') AS TempTB'+' order by '+ @fldSort +' '+ @strFSortType
            else
                    set @strTmp=@SqlSelect+' * from ('+@SqlSelect+' top '+ CAST(@pageSize as VARCHAR(4))+' '+ @fldName+' from '+@tblName
                        +' where '+@ID+' not in('+ @SqlSelect+' top '+ CAST(@pageSize*(@page-2)+@lastcount as Varchar(20)) +' '+ @ID +' from '+@tblName
                        +' where (1>0) '+ @strCondition +' order by '+ @fldSort +' '+ @strSortType+')'
                        + @strCondition +' order by '+ @fldSort +' '+ @strSortType+') AS TempTB'+' order by '+ @fldSort +' '+ @strFSortType
        end   
    end
------返回查询结果-----
set @strSql = @strTmp
exec sp_executesql @strSql

--print  @strSql
搜索更多相关主题的帖子: 前台 后台 nvarchar int 绑定 
2008-07-02 14:48
tomtory
Rank: 1
来 自:重庆
等 级:新手上路
帖 子:705
专家分:0
注 册:2008-6-12
收藏
得分:0 
页面上的代码发上来看看
2008-07-02 14:50
koleal
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2008-7-2
收藏
得分:0 
这是页面上绑定的代码
 protected void ObjectDataSource1_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
    {
        e.InputParameters["tblName"] = "OceanBBSPosts";
        e.InputParameters["fldName"] = "Title";
        e.InputParameters["pageSize"] = 2;
        e.InputParameters["page"] = 2;
        e.InputParameters["fldSort"] = "DateGreated";
        e.InputParameters["ID"] = "PostID";
        e.InputParameters["Counts"] = 0;
      

    }
2008-07-02 14:59
koleal
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2008-7-2
收藏
得分:0 
这是前台显示的代码


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.

<html xmlns="http://www. >
<head runat="server">
    <title>无标题页</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        &nbsp;<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" InsertMethod="Insert"
            OldValuesParameterFormatString="original_{0}" OnSelecting="ObjectDataSource1_Selecting"
            SelectMethod="GetDataBy" TypeName="OceanTableAdapters.OceanBBSPostsTableAdapter"
            UpdateMethod="Update">
            <UpdateParameters>
                <asp:Parameter Name="PostID" Type="Object" />
                <asp:Parameter Name="Title" Type="String" />
                <asp:Parameter Name="PostContent" Type="String" />
                <asp:Parameter Name="DateGreated" Type="DateTime" />
                <asp:Parameter Name="DateModefied" Type="DateTime" />
                <asp:Parameter Name="UserName" Type="String" />
                <asp:Parameter Name="IsTop" Type="Boolean" />
                <asp:Parameter Name="IsBest" Type="Boolean" />
                <asp:Parameter Name="Hits" Type="Int32" />
                <asp:Parameter Name="BBSCategorySubCategorySubID" Type="Object" />
                <asp:Parameter Name="ImageUrl" Type="String" />
                <asp:Parameter Name="BBSCategoryCategoryID" Type="Object" />
                <asp:Parameter Name="Province" Type="String" />
                <asp:Parameter Name="IsActive" Type="Boolean" />
                <asp:Parameter Name="BBSCategoryThreeID" Type="Object" />
                <asp:Parameter Name="Original_PostID" Type="Object" />
            </UpdateParameters>
            <SelectParameters>
                <asp:Parameter DefaultValue="" Name="tblName" Type="String" />
                <asp:Parameter DefaultValue="" Name="fldName" Type="String" />
                <asp:Parameter DefaultValue="" Name="pageSize" Type="Int32" />
                <asp:Parameter DefaultValue="" Name="page" Type="Int32" />
                <asp:Parameter DefaultValue="" Name="fldSort" Type="String" />
                <asp:Parameter DefaultValue="" Name="Sort" Type="Boolean" />
                <asp:Parameter DefaultValue="" Name="strCondition" Type="String" />
                <asp:Parameter DefaultValue="" Name="ID" Type="String" />
                <asp:Parameter DefaultValue="" Name="Dist" Type="Boolean" />
                <asp:Parameter DefaultValue="" Direction="InputOutput" Name="pageCount" Type="Object" />
                <asp:Parameter DefaultValue="" Direction="InputOutput" Name="Counts" Type="Object" />
                <asp:Parameter Direction="InputOutput" Name="strSql" Type="String" />
            </SelectParameters>
            <InsertParameters>
                <asp:Parameter Name="PostID" Type="Object" />
                <asp:Parameter Name="Title" Type="String" />
                <asp:Parameter Name="PostContent" Type="String" />
                <asp:Parameter Name="DateGreated" Type="DateTime" />
                <asp:Parameter Name="DateModefied" Type="DateTime" />
                <asp:Parameter Name="UserName" Type="String" />
                <asp:Parameter Name="IsTop" Type="Boolean" />
                <asp:Parameter Name="IsBest" Type="Boolean" />
                <asp:Parameter Name="Hits" Type="Int32" />
                <asp:Parameter Name="BBSCategorySubCategorySubID" Type="Object" />
                <asp:Parameter Name="ImageUrl" Type="String" />
                <asp:Parameter Name="BBSCategoryCategoryID" Type="Object" />
                <asp:Parameter Name="Province" Type="String" />
                <asp:Parameter Name="IsActive" Type="Boolean" />
                <asp:Parameter Name="BBSCategoryThreeID" Type="Object" />
            </InsertParameters>
        </asp:ObjectDataSource>
        &nbsp;<asp:DataList ID="DataList1" runat="server" DataKeyField="PostID" DataSourceID="ObjectDataSource1">
            <ItemTemplate>
                PostID:
                <asp:Label ID="PostIDLabel" runat="server" Text='<%# Eval("PostID") %>'></asp:Label><br />
                Title:
                <asp:Label ID="TitleLabel" runat="server" Text='<%# Eval("Title") %>'></asp:Label><br />
                PostContent:
                <asp:Label ID="PostContentLabel" runat="server" Text='<%# Eval("PostContent") %>'>
                </asp:Label><br />
                DateGreated:
                <asp:Label ID="DateGreatedLabel" runat="server" Text='<%# Eval("DateGreated") %>'>
                </asp:Label><br />
                DateModefied:
                <asp:Label ID="DateModefiedLabel" runat="server" Text='<%# Eval("DateModefied") %>'>
                </asp:Label><br />
                UserName:
                <asp:Label ID="UserNameLabel" runat="server" Text='<%# Eval("UserName") %>'></asp:Label><br />
                IsTop:
                <asp:Label ID="IsTopLabel" runat="server" Text='<%# Eval("IsTop") %>'></asp:Label><br />
                IsBest:
                <asp:Label ID="IsBestLabel" runat="server" Text='<%# Eval("IsBest") %>'></asp:Label><br />
                Hits:
                <asp:Label ID="HitsLabel" runat="server" Text='<%# Eval("Hits") %>'></asp:Label><br />
                BBSCategorySubCategorySubID:
                <asp:Label ID="BBSCategorySubCategorySubIDLabel" runat="server" Text='<%# Eval("BBSCategorySubCategorySubID") %>'>
                </asp:Label><br />
                ImageUrl:
                <asp:Label ID="ImageUrlLabel" runat="server" Text='<%# Eval("ImageUrl") %>'></asp:Label><br />
                BBSCategoryCategoryID:
                <asp:Label ID="BBSCategoryCategoryIDLabel" runat="server" Text='<%# Eval("BBSCategoryCategoryID") %>'>
                </asp:Label><br />
                Province:
                <asp:Label ID="ProvinceLabel" runat="server" Text='<%# Eval("Province") %>'></asp:Label><br />
                IsActive:
                <asp:Label ID="IsActiveLabel" runat="server" Text='<%# Eval("IsActive") %>'></asp:Label><br />
                CategorySubName:
                <asp:Label ID="CategorySubNameLabel" runat="server" Text='<%# Eval("CategorySubName") %>'>
                </asp:Label><br />
                CategoryThreeName:
                <asp:Label ID="CategoryThreeNameLabel" runat="server" Text='<%# Eval("CategoryThreeName") %>'>
                </asp:Label><br />
                ProvinceName:
                <asp:Label ID="ProvinceNameLabel" runat="server" Text='<%# Eval("ProvinceName") %>'>
                </asp:Label><br />
                BBSCategoryThreeID:
                <asp:Label ID="BBSCategoryThreeIDLabel" runat="server" Text='<%# Eval("BBSCategoryThreeID") %>'>
                </asp:Label><br />
                <br />
            </ItemTemplate>
        </asp:DataList>
        &nbsp;
   
    </div>
    </form>
</body>
</html>
2008-07-02 15:00
雪雨星风
Rank: 1
来 自:北京
等 级:新手上路
威 望:1
帖 子:566
专家分:0
注 册:2007-10-11
收藏
得分:0 
打个断点调试一下看后台取到的是什么

C#发烧友QQ群1:5953354   QQ群2:68096127  QQ群3:30217249  QQ群4:37023079   为了更好方便大家交流学习,请不要重复加群
2008-07-02 15:02
tomtory
Rank: 1
来 自:重庆
等 级:新手上路
帖 子:705
专家分:0
注 册:2008-6-12
收藏
得分:0 
这个控件没有用过的哦  呵呵
2008-07-02 15:05
koleal
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2008-7-2
收藏
得分:0 
没有打断点测试啊,objectdatasource的返回值不知道怎么得到,还有更好的方法吗,
2008-07-02 15:32
雪雨星风
Rank: 1
来 自:北京
等 级:新手上路
威 望:1
帖 子:566
专家分:0
注 册:2007-10-11
收藏
得分:0 
我也没有用过存储过程分页  我一般都是用C#

C#发烧友QQ群1:5953354   QQ群2:68096127  QQ群3:30217249  QQ群4:37023079   为了更好方便大家交流学习,请不要重复加群
2008-07-02 15:34
koleal
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2008-7-2
收藏
得分:0 
试了下,测试了下Counts的返回值是0,确实没有返回对象,不知道为什么啊,在存储过程中测试时是有返回值的啊,象这样,
运行[dbo].[PageList] ( @tblName = OceanBBSPosts, @fldName = Title, @pageSize = 10, @page = 10, @fldSort = DateGreated, @Sort = true, @strCondition = <DEFAULT>, @ID = PostID, @Dist = <DEFAULT>, @pageCount = <DEFAULT>, @Counts = <DEFAULT>, @strSql = <DEFAULT> ).

Title                                                                                                                        
-----------------------------------------------------------------------------------------------------------------------------
压力表的量程和精度选择方法以及安装和使用的要求                                                                                                      
五越办照                                                                                                                          
什么是水的浑浊度?                                                                                                                     
不锈钢紧固件的常识                                                                                                                     
水泵的轴承温度高的原因                                                                                                                  
化工泵选型                                                                                                                        
反渗透预处理                                                                                                                        
废水回用流程图                                                                                                                       
发展中水回用技术的重要意义                                                                                                                 
无机膜应用领域                                                                                                                       
没有行受影响。
(返回 10 行)
@pageCount = 123
@Counts = 1230
@strSql = select  top 10 Title from OceanBBSPosts where PostID not in(select  top 90 PostID from OceanBBSPosts order by DateGreated  DESC ) order by DateGreated  DESC
@RETURN_VALUE = 0
完成 [dbo].[PageList] 运行。
2008-07-02 15:35
快速回复:为什么后台有值,前台却没有显示
数据加载中...
 
   



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

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