I have an array that holds a product id and the quantity, acting as a shopping basket.
My present loop allows me to insert the data into my table when the array count is 1:
var p = Basket.arrayList;
for (int i = 0; i < p.Count; i++)
// Loop through List
{
var ProductId = p[i][0];
var Quantity = p[i][1];
itemsQueryCommand.CommandText = "INSERT INTO tOrderItems (orderId, name, quantity) VALUES (@OrderId, @name, @quantity )";
itemsQueryCommand.Parameters.AddWithValue("@OrderId", id);
itemsQueryCommand.Parameters.AddWithValue("@name", ProductId);
itemsQueryCommand.Parameters.AddWithValue("@quantity", Quantity);
itemsQueryCommand.ExecuteNonQuery();
}
If the array holds any more than 1 it throws an error saying; "The variable name '@OrderId' has already been declared. Variable names must be unique within a query batch or stored procedure."
I really don't know how to fix this... Please help