In the following code, I got following error.
An exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll but was not handled in user code
Additional information: Index was out of range. Must be non-negative and less than the size of the collection.
the Code :
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;
}
}
}
if i want to active the product after that & i need to set the products in the basket by the id if any one have any idea about that please tell me in a comment
Try to use the name of each column:
Quantity.Text = reader["Quantity"] as string;
instead of
Quantity.Text = reader[1] as string;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.