C# aspx.net指定的参数超出有效值的范围
错误为C# aspx.net指定的参数超出有效值的范围,c#,asp.net,C#,Asp.net,错误为strProductId=row0.Cells[1].Text。它表明: 指定的参数超出了有效值的范围 有人能解释一下代码有什么问题吗?多谢各位 //retrieve the product ID from the first row of the DetailsView DetailsViewRow row0 = DetailsView2.Rows[0]; strProductId = row0.Cells[1].Text; //extract the QuantityOnHand f
strProductId=row0.Cells[1].Text代码>。它表明:
指定的参数超出了有效值的范围
有人能解释一下代码有什么问题吗?多谢各位
//retrieve the product ID from the first row of the DetailsView
DetailsViewRow row0 = DetailsView2.Rows[0];
strProductId = row0.Cells[1].Text;
//extract the QuantityOnHand from the database - based on the product ID
strSQLSelect = "SELECT pQty FROM Products WHERE pItemID = @ProductId";
cmd = new OleDbCommand(strSQLSelect, mDB);
cmd.Parameters.Add("@ProductId", OleDbType.VarChar).Value = strProductId;
object oQty = cmd.ExecuteScalar();
intQuantityOnHand = (int)oQty
请检查row0.Cells[1]的值。Text
row0.Cells没有数组索引1。请调试下面的代码
DetailsViewRow row0 = DetailsView2.Rows[0];
if(row0.cell.count > 0)
{
strProductId = row0.Cells[1].Text;
}
行0没有单元格[1]元素,是否在debuggerPlease-->中检查了单元格?我已检查了单元格,它看起来很好。@Kevin123是它在单元格[1]和单元格[1]中具有值。Text。还要检查单元格[1]。vs debug中的文本