/* ##################################################################### # Q5 # itemStoreSold._ITEMCODE # itemStoreSold._STORECODE # itemStoreSold._SOLD ##################################################################### */ public static List <ItemStoreSold> GetItemsStoresSold() { string Q5Query = " select t.STORECODE, i.ITEMCODE ,sum(i.quantity) " + " as sold from includes i " + " inner join TRANSACTIONS t on i.TRANSACTIONCODE = t.TRANSACTIONCODE " + " group by t.STORECODE, i.ITEMCODE " + " order by t.STORECODE asc, sold desc, i.ITEMCODE asc "; List <ItemStoreSold> itemStoreSolds = new List <ItemStoreSold>(); if (Connect()) { //we are going to call query called Q5 using (SqlCommand sqlCommand = new SqlCommand()) { sqlCommand.CommandType = CommandType.Text; sqlCommand.CommandText = Q5Query; sqlCommand.Connection = _Connection; SqlDataReader reader; try { reader = sqlCommand.ExecuteReader(); } catch (Exception ex) { return(null); } //Converting query results to PersonPhoneAddress objects while (reader.Read()) { ItemStoreSold itemStoreSold = new ItemStoreSold(); itemStoreSold._STORECODE = Convert.ToInt32(reader[0]); itemStoreSold._ITEMCODE = Convert.ToInt32(reader[1]); itemStoreSold._SOLD = Convert.ToInt32(reader[2]); itemStoreSolds.Add(itemStoreSold); } reader.Close(); } } return(itemStoreSolds); }
/* ##################################################################### # Q5 # itemStoreSold._ITEMCODE # itemStoreSold._STORECODE # itemStoreSold._SOLD ##################################################################### */ public static List <ItemStoreSold> GetItemsStoresSold() { List <ItemStoreSold> itemStoreSolds = new List <ItemStoreSold>(); ItemStoreSold itemStoreSold; if (Connect()) { using (SqlCommand sqlCommand = new SqlCommand("Q5", _Connection)) { sqlCommand.CommandType = CommandType.StoredProcedure; sqlCommand.CommandText = "GetItemsStoresSold"; SqlDataReader reader; try { reader = sqlCommand.ExecuteReader(); } catch (Exception ex) { return(null); } while (reader.Read()) { itemStoreSold = new ItemStoreSold(); itemStoreSold._STORECODE = Convert.ToInt32(reader[0]); itemStoreSold._ITEMCODE = Convert.ToInt32(reader[1]); itemStoreSold._SOLD = Convert.ToInt32(reader[2]); itemStoreSolds.Add(itemStoreSold); } reader.Close(); } } return(itemStoreSolds); }