public List<CountryViewModel> GetALLCountryViewByName(string searchName) { int count = 0; string query = "Select * from GetCountryInfo where Name LIKE '%[" + searchName + "]%' "; SqlCommand command = new SqlCommand(query, connection); connection.Open(); SqlDataReader reader = command.ExecuteReader(); List<CountryViewModel> countryView = new List<CountryViewModel>(); while (reader.Read()) { count = count + 1; CountryViewModel countryViewModelObj = new CountryViewModel(); countryViewModelObj.SL = count; countryViewModelObj.Name = reader["Name"].ToString(); byte[] binaryString = (byte[])(reader["About"]); countryViewModelObj.About = Encoding.UTF8.GetString(binaryString); //countryViewModelObj.About = reader["About"].ToString(); countryViewModelObj.NoOfCities = Convert.ToInt32(reader["No Of Cities"].ToString()); countryViewModelObj.NoOfCityDwellers = Convert.ToInt32(reader["No Of City Dwellers"].ToString()); countryView.Add(countryViewModelObj); } connection.Close(); int datacount = countryView.Count; if (datacount == 0) { return null; } return countryView; }
///////////////////////////// public List<CountryViewModel> GetALLCountryView() { int count = 0; string query = "Select * from GetCountryInfo ORDER BY Name"; SqlCommand command = new SqlCommand(query, connection); connection.Open(); SqlDataReader reader = command.ExecuteReader(); List<CountryViewModel> countryView = new List<CountryViewModel>(); while (reader.Read()) { count = count + 1; CountryViewModel countryViewModelObj = new CountryViewModel(); countryViewModelObj.SL = count; countryViewModelObj.Name = reader["Name"].ToString(); byte[] binaryString = (byte[])(reader["About"]); countryViewModelObj.About = Encoding.UTF8.GetString(binaryString); countryViewModelObj.NoOfCities = Convert.ToInt32(reader["No. of cities"].ToString()); countryViewModelObj.NoOfCityDwellers = Convert.ToInt32(reader["No. of city dwellers"].ToString()); countryView.Add(countryViewModelObj); } connection.Close(); return countryView; }