/* ##################################################################### # Q7 # bestSeller._ItemName # bestSeller._Quantity ##################################################################### */ public static Best_Seller GetBestSeller() { Best_Seller bestSeller = new Best_Seller(); return(bestSeller); }
/* ##################################################################### # Q7 # bestSeller._ItemName # bestSeller._Quantity ##################################################################### */ public static Best_Seller GetBestSeller() { Best_Seller bestSeller = new Best_Seller(); if (Connect()) { using (SqlCommand sqlCommand = new SqlCommand("Q7", _Connection)) { sqlCommand.CommandType = CommandType.StoredProcedure; sqlCommand.CommandText = "sp_GetBestSeller"; SqlDataReader reader; try { reader = sqlCommand.ExecuteReader(); } catch (Exception ex) { return(null); } while (reader.Read()) { bestSeller = new Best_Seller(); bestSeller._ItemName = Convert.ToString(reader[0]); bestSeller._Quantity = Convert.ToInt32(reader[1]); } reader.Close(); } } return(bestSeller); }
/* ##################################################################### # Q7 # bestSeller._ItemName # bestSeller._Quantity ##################################################################### */ public static Best_Seller GetBestSeller() { string Q7Query = " select top 1 it.ITEMCODE, sum(i.QUANTITY) as sold from item it " + " inner join INCLUDES i on " + " it.ITEMCODE= i.ITEMCODE " + " group by it.ITEMCODE " + " order by sold desc, it.ITEMCODE asc "; Best_Seller bestSeller = new Best_Seller(); if (Connect()) { //we are going to call query called Q7 using (SqlCommand sqlCommand = new SqlCommand()) { sqlCommand.CommandType = CommandType.Text; sqlCommand.CommandText = Q7Query; sqlCommand.Connection = _Connection; SqlDataReader reader; try { reader = sqlCommand.ExecuteReader(); } catch (Exception ex) { return(null); } //Converting query results to PersonPhoneAddress objects while (reader.Read()) { bestSeller._ItemName = Convert.ToString(reader[0]); bestSeller._Quantity = Convert.ToInt32(reader[1]); } reader.Close(); } } return(bestSeller); }