日期:2014-05-17 浏览次数:20952 次
using System; using System.Collections.Generic; using System.Linq; using System.Text; using NorthwindPrjModel; using System.Data.SqlClient; namespace NorthwindPrjDAL { public class OrderDAL { public List<Order> GetAllOrders() { string sql = "SELECT OrderID,Freight,ShipName,ShipAddress,ShipCity,ShipCountry FROM Orders"; SqlDataReader sdr = SqlHelper.GetReader(sql); List<Order> orders = new List<Order>(); while (sdr.Read()) { Order order = new Order(); order.OrderID = sdr.GetInt32(0); order.Freight = sdr.GetDecimal(1); order.ShipName = sdr.GetString(2); order.ShipAddress = sdr.GetString(3); order.ShipCity = sdr.GetString(4); order.ShipCountry = sdr.GetString(5); orders.Add(order); } sdr.Close(); return orders; } public List<string> GetShipCountries() { string sql = "select distinct ShipCountry from orders"; SqlDataReader sdr = SqlHelper.GetReader(sql); List<string> countries = new List<string>(); while (sdr.Read()) { countries.Add(sdr.GetString(0)); } sdr.Close(); return countries; } } }