2016-05-28 10 views
-1

次のコードでは、次のエラーが発生しました。c#QueryString exception

型「System.ArgumentOutOfRangeExceptionが」の例外が がmscorlib.dllで発生したが、ユーザーコード

追加情報で処理されませんでした:インデックスが範囲外でした。負ではない で、コレクションのサイズ未満である必要があります。

コード:

protected void Page_Load(object sender, EventArgs e) 
{ 
    Prid.Text = Request.QueryString[0]; 
    using (SqlConnection connection = ConnectionManager.GetConnection()) 
    { 
     string cmd = "SELECT ImageColor, Quantity, ProductName, Price, ScreenSize, ScreenType, Processor, Internal_Memory, Ram, SD_Card, Camera, Bettery From Mobtabspecifications WHERE Mobtabspecifications.Prid ='" + Prid.Text+"'"; 
     SqlCommand command = new SqlCommand(cmd, connection); 
     SqlDataReader reader = command.ExecuteReader(); 
     while (reader.Read()) 
     { 
      img.ImageUrl = "../image/"+ reader[0] as string; 
      Quantity.Text = reader[1] as string; 
      PrName.Text = reader[2] as string; 
      PrPrice.Text = reader[3] as string; 
      SSize.Text = reader[4] as string; 
      SType.Text = reader[5] as string; 
      Prpower.Text = reader[6] as string; 
      Intmemory.Text = reader[7] as string; 
      Ram.Text = reader[8] as string; 
      sdcard.Text = reader[9] as string; 
      Camera.Text = reader[10] as string; 
      Bettery.Text = reader[11] as string; 
      break; 
     } 

    } 
} 

私はいずれかがそのことについてどんな考えを持っている場合は、idによってバスケットに製品を設定する必要があること&後にアクティブ製品にしたいなら、私にして教えてくださいコメント

+1

Request.QueryStringには要素が含まれていません –

+1

無関係のSQLインジェクションサンプルは削除してください。 –

+0

このページに渡すクエリ文字列とは何ですか?文字列の連結を避け、パラメータ化されたクエリを使用してSQLインジェクションを防止します。 http://bobby-tables.comを参照 – Spidey

答えて

0

各列の名前を使用してみてください:

Quantity.Text = reader["Quantity"] as string; 

の代わり