Reputation: 35
I have my "orders" table looks like:
orderId CustomerName
1 customer1
2 customer2
3 customer1
4 customer1
and I have my code which only get one orderId
SqlCommand command = new SqlCommand("SELECT orderId FROM orders WHERE CustomerName='"+name+"'", connection);
SqlDataReader reader = command.ExecuteReader();
if (reader.Read()){
MyOrders order1 = new MyOrders(reader.GetInt32(0));
orders.Add(order1);
}
return orders.ToArray();
how to get all orderId 1,3,4 with customer1?
Upvotes: 0
Views: 671
Reputation: 48550
Use a loop to add all orders. Like this
while (reader.Read())
{
MyOrders order1 = new MyOrders(reader.GetInt32(reader("orderId")));
orders.Add(order1);
}
Upvotes: 2