Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/270.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# aspx.net指定的参数超出有效值的范围_C#_Asp.net - Fatal编程技术网

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中的文本