/* ##################################################################### # Q13 # storeLocation._STORECODE # storeLocation._Distance # storeLocation._X # storeLocation._Y ##################################################################### */ public static List <StoreDistance> FindStoresInRange(double X, double Y, int range) { List <StoreDistance> neareststores = new List <StoreDistance>(); if (Connect()) { //we are going to call query called Q11 using (SqlCommand sqlCommand = new SqlCommand("Q13", _Connection)) { sqlCommand.CommandType = CommandType.StoredProcedure; sqlCommand.Parameters.Add("@X", SqlDbType.VarChar).Value = X.ToString(); sqlCommand.Parameters.Add("@Y", SqlDbType.VarChar).Value = Y.ToString(); sqlCommand.Parameters.Add("@range", SqlDbType.VarChar).Value = range.ToString(); SqlDataReader reader; try { reader = sqlCommand.ExecuteReader(); } catch (Exception ex) { return(null); } //Converting query results to PersonPhoneAddress objects while (reader.Read()) { StoreDistance storeLocation = new StoreDistance(); storeLocation._STORECODE = Convert.ToInt32(reader[0]); storeLocation._Distance = Convert.ToString(reader[1]); storeLocation._X = Convert.ToInt32(reader[2]); storeLocation._Y = Convert.ToInt32(reader[3]); neareststores.Add(storeLocation); } reader.Close(); } } return(neareststores); }
/* ##################################################################### # Q13 # storeLocation._STORECODE # storeLocation._Distance # storeLocation._X # storeLocation._Y ##################################################################### */ public static List <StoreDistance> FindStoresInRange(double X, double Y, int range) { List <StoreDistance> neareststores = new List <StoreDistance>(); StoreDistance storeLocation; if (Connect()) { using (SqlCommand sqlCommand = new SqlCommand("Q13", _Connection)) { sqlCommand.CommandType = CommandType.StoredProcedure; sqlCommand.CommandText = "sp_FindStoresInRange"; sqlCommand.Parameters.Add("@X", SqlDbType.VarChar).Value = X; sqlCommand.Parameters.Add("@Y", SqlDbType.VarChar).Value = Y; sqlCommand.Parameters.Add("@RANGE", SqlDbType.VarChar).Value = range; SqlDataReader reader; try { reader = sqlCommand.ExecuteReader(); } catch (Exception ex) { return(null); } while (reader.Read()) { storeLocation = new StoreDistance(); storeLocation._STORECODE = Convert.ToInt32(reader[0]); storeLocation._Distance = Convert.ToString(reader[1]); storeLocation._X = Convert.ToInt32(reader[2]); storeLocation._Y = Convert.ToInt32(reader[3]); neareststores.Add(storeLocation); } reader.Close(); } } return(neareststores); }