public SizeDTO FindPriceBySize(int productID, int sizeProduct) { SizeDTO size; ProductDTO product; string queryString = "SELECT * FROM dbo.Size WHERE unitSize = @unitSize AND productID = @id"; try { //The connection is automatically closed at the end of the using block. using (SqlConnection con = new SqlConnection(ConnectionString)) { using (SqlCommand cmd = new SqlCommand(queryString, con)) { cmd.Parameters.AddWithValue("@unitSize", SqlDbType.Decimal).Value = sizeProduct; cmd.Parameters.AddWithValue("@id", SqlDbType.Int).Value = productID; con.Open(); SqlDataReader reader = cmd.ExecuteReader(); if (reader.Read()) { size = new SizeDTO(); product = new ProductDTO(); size = GenerateDetail(reader, product, size); //return product instance as data object Debug.Print("SizeDAL: /FindByProduct/ " + size.GetID().ToString()); return(size); } } } } catch (Exception e) { e.GetBaseException(); } return(null); }
public List <SizeDTO> FindAll() { SizeDTO size; ProductDTO product; List <SizeDTO> results = new List <SizeDTO>(); string queryString = "SELECT * FROM dbo.Size"; try { //The connection is automatically closed at the end of the using block. using (SqlConnection con = new SqlConnection(ConnectionString)) { using (SqlCommand cmd = new SqlCommand(queryString, con)) { con.Open(); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { size = new SizeDTO(); product = new ProductDTO(); size = GenerateDetail(reader, product, size); //return product instance as data object Debug.Print("SizeDAL: /FindByAll/ " + size.GetID().ToString()); results.Add(size); } } } } catch (Exception e) { e.GetBaseException(); } return(results); }