public SaleLineItem Get(int id) { using (SqlConnection connection = conn.OpenConnection()) { using (SqlCommand cmd = connection.CreateCommand()) { cmd.CommandText = "SELECT * FROM SaleLineItem WHERE id = @id"; cmd.Parameters.AddWithValue("id", id); //Finding and fetching result from SQL database using DBproduct to also find the corresponding product for the SaleLineItem DBProduct dbProduct = new DBProduct(); SqlDataReader reader = cmd.ExecuteReader(); bool isRead = reader.Read(); return(new SaleLineItem(reader.GetInt32(0), dbProduct.Get(reader.GetInt32(1)), reader.GetInt32(2), reader.GetInt32(3))); } } }
public List <SaleLineItem> GetAll() { List <SaleLineItem> SaleLineItemList = new List <SaleLineItem>(); using (SqlConnection connection = conn.OpenConnection()) { using (SqlCommand cmd = connection.CreateCommand()) { cmd.CommandText = "SELECT * FROM SaleLineItem"; SqlDataReader reader = cmd.ExecuteReader(); DBProduct dbProduct = new DBProduct(); while (reader.Read()) { SaleLineItem sli = new SaleLineItem(reader.GetInt32(0), dbProduct.Get(reader.GetInt32(1)), reader.GetInt32(2), reader.GetInt32(3)); SaleLineItemList.Add(sli); } } } return(SaleLineItemList); }