我的“订单”表格如下:
orderId CustomerName
1 customer1
2 customer2
3 customer1
4 customer1
我的代码只有一个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();
如何使用customer1获取所有orderId 1,3,4?
答案 0 :(得分:2)
使用循环添加所有订单。喜欢这个
while (reader.Read())
{
MyOrders order1 = new MyOrders(reader.GetInt32(reader("orderId")));
orders.Add(order1);
}