2017-01-27 11 views
-1

エラーはstrProductId = row0.Cells[1].Text;です。表示されます:aspx.net指定された引数が有効な値の範囲外です

指定された引数が有効な値の範囲外です。

誰かがコードの何が間違っていると説明できますか?ありがとうございました。

//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 
+2

ROW0を使用すると、デバッガ –

+0

にしてくださいセルを確認しなかった、細胞[1]の要素を持っていません。 – Filburt

+0

私は細胞をチェックして、それは正常に見えます。 – Kevin123

答えて

1

配列インデックス1.以下のコードをデバッグしてください必要はありませんrow0.Cells[1].Text row0.Cellsの値を確認してください。 > [編集] < - - あなたのポスト - コードは、コメントで読めない

DetailsViewRow row0 = DetailsView2.Rows[0]; 
if(row0.cell.count > 0) 
{ 
    strProductId = row0.Cells[1].Text; 
} 
関連する問題