示例#1
0
 public List <CountryViewerModel> GetCountryInformation()
 {
     try
     {
         string query = "SELECT * FROM CountryInformationWithCity ORDER BY Name";
         CommandObj.CommandText = query;
         List <CountryViewerModel> countryViewerModels = new List <CountryViewerModel>();
         ConnectionObj.Open();
         SqlDataReader reader = CommandObj.ExecuteReader();
         while (reader.Read())
         {
             CountryViewerModel countryViewerModel = new CountryViewerModel();
             countryViewerModel.CountryName      = reader["Name"].ToString();
             countryViewerModel.AboutCountry     = reader["About"].ToString();
             countryViewerModel.NoOfCities       = Convert.ToInt32(reader["Total_City"].ToString());
             countryViewerModel.NoOfCityDwellers = Convert.ToInt64(reader["Total_Dwellers"].ToString());
             countryViewerModels.Add(countryViewerModel);
         }
         reader.Close();
         return(countryViewerModels);
     }
     catch (Exception exception)
     {
         throw new Exception("Unable to collect country Information", exception);
     }
     finally
     {
         ConnectionObj.Close();
         CommandObj.Dispose();
     }
 }
示例#2
0
        //-------------------Problem here------------------
        public List <CountryViewerModel> GetCountryInformatinByName(string countryName)
        {
            string query = "SELECT * FROM CountryInformationWithCity  WHERE Name LIKE '%" + countryName + "%' ORDER BY Name";

            CommandObj.CommandText = query;
            List <CountryViewerModel> countryViewerModels = new List <CountryViewerModel>();

            ConnectionObj.Open();
            SqlDataReader reader = CommandObj.ExecuteReader();

            while (reader.Read())
            {
                CountryViewerModel countryViewer = new CountryViewerModel();
                countryViewer.CountryName      = reader["Name"].ToString();
                countryViewer.AboutCountry     = reader["About"].ToString();
                countryViewer.NoOfCities       = Convert.ToInt32(reader["Total_City"].ToString());
                countryViewer.NoOfCityDwellers = Convert.ToInt64(reader["Total_Dwellers"].ToString());
                countryViewerModels.Add(countryViewer);
            }
            reader.Close();
            ConnectionObj.Close();

            return(countryViewerModels);
        }