首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

为什么会报 索引 -4 不是非负数且小于总行数。 这个异常

2012-02-06 
为什么会报 索引 -4 不是非负数且小于总行数。这个错误后台代码如下idsCInt(Request( companyid ))dsNe

为什么会报 索引 -4 不是非负数且小于总行数。 这个错误
后台代码如下  
                ids   =   CInt(Request( "companyid "))
                ds   =   New   DataSet
                user_id   =   (Convert.ToString(Request.QueryString( "user ")))
                Dim   myconn   As   SqlConnection   =   New   SqlConnection(ConfigurationSettings.AppSettings( "connectionString "))
                adapter   =   New   SqlDataAdapter( "Select   *   from   qyry   where   user_id= ' "   &   user_id   &   " '   and   lei= ' "   &   "qyry "   &   " '   order   by   id   desc ",   myconn)
                ds   =   New   DataSet
                adapter.Fill(ds,   "Orders ")
                Dim   pp   As   New   PagedDataSource
                pp.DataSource   =   ds.Tables( "Orders ").DefaultView
                pp.AllowPaging   =   True
                pp.PageSize   =   4
                Dim   nPageCount   As   Integer   '保存总共的数据页面数目
                Dim   a   =   ds.Tables( "Orders ").Rows.Count   '保存记录总数
                Dim   nPage   As   Integer     '存放要浏览当前数据页面号
                If   pp.PageCount   Mod   pp.PageSize   >   0   Then
                        nPageCount   =   a   \   pp.PageSize
                        nPageCount   +=   1
                End   If
                nPage   =   Convert.ToInt32(Request.QueryString( "Page "))
                If   Request.QueryString( "Page ")   <   1   Then
                        nPage   =   1
                End   If
                If   Request.QueryString( "Page ")   >   nPageCount   Then
                        nPage   =   nPageCount
                End   If
                pp.CurrentPageIndex   =   nPage   -   1
                lblPageCount.Text   =   "总共 "   &   a.ToString()   +   "条纪录 "
                lblmsg.Text   =   ( "&nbsp; "   &   "页次: "   &   nPage.ToString()   &   "/ "   &   nPageCount.ToString())


                lblmsg.Text   +=   ( "&nbsp;&nbsp; <A   HREF   =   " " "   &   Request.CurrentExecutionFilePath   &   "?user= "   &   user_id   &   "&companyid= "   &   ids   &   "&page= "   &   (1).ToString()   &   " " "> 首     页   </A   > ")
                '   If   Not   pp.IsFirstPage   Then
                lblmsg.Text   +=   ( "   <A   HREF   =   " " "   &   Request.CurrentExecutionFilePath   &   "?user= "   &   user_id   &   "&companyid= "   &   ids   &   "&page= "   &   Convert.ToString(nPage   -   1)   &   " " "   > 上一页 </A   >   ")
                '   End   If
                '   If   Not   pp.IsLastPage   Then
                lblmsg.Text   +=   ( " <A   HREF   = " " "   &   Request.CurrentExecutionFilePath   &   "?user= "   &   user_id   &   "&companyid= "   &   ids   &   "&page= "   &   Convert.ToString(nPage   +   1)   &   " " "   > 下一页 </A   >   ")
                '     End   If
                lblmsg.Text   +=   ( " <A   HREF   =   " " "   &   Request.CurrentExecutionFilePath   &   "?user= "   &   user_id   &   "&companyid= "   &   ids   &   "&page= "   &   (nPageCount).ToString()   &   " " "   > 尾     页 </A   > ")
                dstmsg.DataSource   =   pp
                dstmsg.DataBind()

前台是:
<asp:DataList   ID= "dstmsg "   runat= "server "   BorderColor= "ActiveBorder "   BorderStyle= "None ">
                                                                                                    <itemtemplate>
                                                                                                        <table   width= "280 "   border= "0 "   cellspacing= "0 "   cellpadding= "0 ">


                                                                                                            <tr>
                                                                                                                <td   height= "25 ">   <a   href= 'qyry4.aspx?id= <%#container.dataitem( "id ")%> &user= <%#container.dataitem( "user_id ")%> 'title= ' <%#   Container.DataItem(   "mc "   ).ToString()   %> '> <%#   Left(DataBinder.Eval(Container.DataItem, "mc ").ToString(),22)%> </a> </td>
                                                                                                            </tr>
                                                                                                        </table>
                                                                                                        <table   width= "100% "   border= "0 "   cellspacing= "0 "   cellpadding= "0 ">
                                                                                                            <tr>
                                                                                                                <td   width= "280 "   height= "1 "   background= "image/line.jpg "> </td>
                                                                                                            </tr>


                                                                                                        </table>
                                                                                                    </itemtemplate>
                                                                                                </asp:DataList>
                                                                                                    <br>
                                                                                                    <asp:Label   ID= "lblPageCount "   runat= "server "> </asp:Label>
                                                                                                <asp:Label   ID= "lblmsg "   runat= "server "> </asp:Label>

然后运行以后前台只能读出个数   分页是   1/0   谁帮慢看下

[解决办法]
If pp.PageCount Mod pp.PageSize > 0 Then
nPageCount = a \ pp.PageSize
nPageCount += 1
End If
----------------------------------
这个改下
If pp.PageCount Mod pp.PageSize > 0 Then
nPageCount = a \ pp.PageSize
nPageCount += 1
else
nPageCount=a \ pp.pagesize

End If

热点排行