索引0要么为负数,要么大于行数。

您所在的位置:网站首页 索引0不是为负数 索引0要么为负数,要么大于行数。

索引0要么为负数,要么大于行数。

2024-07-09 13:21| 来源: 网络整理| 查看: 265

我不断收到“索引0为负或以上行计数”的错误消息,该错误消息将SQL中的特定行声明为主题行。我试过看其他例子,但我想不出如何解决这个具体的问题。从我的POV中,SQL不是一个问题,否则一切都会正确读取。

代码:

代码语言:javascript复制private Product GetSelectedProduct() { DataView productsTable = (DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty); productsTable.RowFilter = string.Format("ProductID = '{0}'", ddlProducts.SelectedValue); DataRowView row = (DataRowView)productsTable[0]; Product p = new Product(); p.ProductID = row["ProductID"].ToString(); p.Name = row["Name"].ToString(); p.ShortDescription = row["ShortDescription"].ToString(); p.LongDescription = row["LongDescription"].ToString(); p.UnitPrice = (decimal)row["UnitPrice"]; p.ImageFile = row["ImageFile"].ToString(); return p; }

服务器错误:

描述:是在执行当前web请求时发生的一个未处理的异常。请查看堆栈跟踪以获得有关错误的更多信息,以及它起源于代码的位置。 异常详细信息: System.IndexOutOfRangeException:索引0为负数或大于行数。

堆栈跟踪:

代码语言:javascript复制[IndexOutOfRangeException: Index 0 is either negative or above rows count.] System.Data.DataView.GetRow(Int32 index) +1788553 System.Data.DataView.get_Item(Int32 recordIndex) +13 Order.GetSelectedProduct() in f:\Year 2\Internet Applications Programming\Assignment 2\Lab 3 - 06-03-17\Ex04Cart\Order.aspx.cs:23 Order.Page_Load(Object sender, EventArgs e) in f:\Year 2\Internet Applications Programming\Assignment 2\Lab 3 - 06-03-17\Ex04Cart\Order.aspx.cs:12 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51 System.Web.UI.Control.OnLoad(EventArgs e) +95 System.Web.UI.Control.LoadRecursive() +59 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2952


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3