| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1965 人关注过本帖
标题:[求助]索引 -10 不是为负数,就是大于行数。请问这是什么错误啊?
只看楼主 加入收藏
twind
Rank: 1
等 级:新手上路
帖 子:50
专家分:0
注 册:2005-9-5
收藏
 问题点数:0 回复次数:1 
[求助]索引 -10 不是为负数,就是大于行数。请问这是什么错误啊?

源文件如下:
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Page Language="VB" Debug="true" %>
<%@ Import Namespace="System.Web.UI.Page" %>

<html>
<head>
<style type="text/css">
<!--
td {
font-size: 12px;
text-decoration: none;
}
-->
</style>
数据库读取测试</head>
<script language="VB" runat="server">

Sub Page_Load(ByVal Src As Object, ByVal E As EventArgs)

Dim DS As DataSet
'Dim MyConnection As SQLConnection
'Dim MyCommand As SQLDataSetCommand
Dim MyConnection As SqlConnection = New SqlConnection("server='th1';uid=sa;pwd=;database=100lake")

Dim MyCommand As SqlDataAdapter = New SqlDataAdapter("select * from admin", MyConnection)
DS = New DataSet()
MyCommand.Fill(DS, "admin")
'MyDataGrid.DataSource = DS.Tables("admin").DefaultView
Dim pp As System.Data.DataView = New System.Data.DataView(DS.Tables("admin"))
'MyDataGrid.DataBind()
Dim objPds As PagedDataSource = New PagedDataSource()
objPds.DataSource = pp
objPds.AllowPaging = True
'objPds.PageSize = "5"
Dim curPage
If (Request.QueryString("Page") = "") Then

curPage = Convert.ToInt32(Request.QueryString("Page"))

Else
curPage = 1
End If

objPds.CurrentPageIndex = curPage - 1
label1.Text = "当前是第" + curPage.ToString() + "页"
Hyperlink1.NavigateUrl = "default.aspx?Page=1"
Hyperlink4.NavigateUrl = "default.aspx?Page=" + Convert.ToString(objPds.PageCount)

If objPds.IsFirstPage = False Then
HyperLink3.NavigateUrl = "default.aspx?Page=" + Convert.ToString(curPage - 1)
End If

If objPds.IsLastPage = False Then

HyperLink2.NavigateUrl = "default.aspx?Page=" + Convert.ToString(curPage + 1)
End If

MyDataGrid.DataSource = objPds
MyDataGrid.DataBind()


End Sub
</script>
<center>
<body>
<h3><font face="Verdana">Page_load事件演示</font></h3>
<asp:DataList ID="MyDataGrid" RepeatColumns="1" RepeatLayout="Flow" runat="server">
<itemtemplate>
<table style="border-collapse:collapse" width="700" border="0" align="center" cellpadding="2" cellspacing="1" bgcolor="#000000">
<tr bgcolor="#ffffff">

<td width="100" height="22"><span class="topinc">用户名:&nbsp;&nbsp;</span></td>
<td><%# DataBinder.Eval(Container.DataItem,"admuser") %></td>
</tr>
<tr bgcolor="#ffffff">

<td width="100" height="22"><span class="topinc">密码:&nbsp;&nbsp;</span></td>
<td><%# DataBinder.Eval(Container.DataItem,"admpwd") %></td>
</tr>
<tr bgcolor="#ffffff">

<td width="100" height="22"><span class="topinc">权限:&nbsp;&nbsp;</span></td>
<td><%# DataBinder.Eval(Container.DataItem,"admqx") %></td>
</tr>
</table>

</itemtemplate>
</asp:DataList>
<table cellSpacing="1" cellPadding="2" width="700" align="center" bgColor="#000000" border="0">
<tbody>
<tr>
<TD align="right" bgColor="#ffffff" height="20"><asp:label id="Label1" runat="server" height="18"></asp:label><asp:hyperlink id="Hyperlink1" runat="server" Width="41" Height="16px">首 页</asp:hyperlink><asp:hyperlink id="HyperLink3" runat="server" Width="41" Height="16px">上一页</asp:hyperlink><asp:hyperlink id="HyperLink2" runat="server" Width="41" Height="16px">下一页</asp:hyperlink><asp:hyperlink id="Hyperlink4" runat="server" Width="41" Height="16px">尾 页</asp:hyperlink></FONT></TD>
</tr>
</tbody>
</table>
</body>
</center>
</html>


错误如下:
索引 -10 不是为负数,就是大于行数。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.IndexOutOfRangeException: 索引 -10 不是为负数,就是大于行数。

源错误:


行 60:
行 61: MyDataGrid.DataSource = objPds
行 62: MyDataGrid.DataBind()
行 63:
行 64:

请大侠解答一下,Thank You!

搜索更多相关主题的帖子: 索引 负数 数据库 Import 
2006-08-15 16:33
twind
Rank: 1
等 级:新手上路
帖 子:50
专家分:0
注 册:2005-9-5
收藏
得分:0 

没人知道吗?自己顶个啊


-------常在江湖飘,那能不挨刀-------
2006-08-15 17:00
快速回复:[求助]索引 -10 不是为负数,就是大于行数。请问这是什么错误啊?
数据加载中...
 
   



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

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