public List <CountryViews> SearchByCountryName(string countryName) { List <CountryViews> countryViewList = new List <CountryViews>(); SqlConnection connection = new SqlConnection(connectionString); string query = "Select * from CountryViews Where Name Like '%'+ @countryName+'%'"; connection.Open(); SqlCommand command = new SqlCommand(query, connection); command.Parameters.Clear(); command.Parameters.Add("@countryName", SqlDbType.VarChar); command.Parameters["@countryName"].Value = countryName; SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { CountryViews countryViews = new CountryViews(); countryViews.Name = reader["Name"].ToString(); countryViews.About = reader["About"].ToString(); countryViews.NoOfCities = Convert.ToInt32(reader["NoOfCities"]); countryViews.NoOfDwellers = Convert.ToInt32(reader["NoOfDwellers"]); countryViewList.Add(countryViews); } connection.Close(); return(countryViewList); }
protected void countrySearchButton_Click(object sender, EventArgs e) { string message = ""; CountryViews countryViews = new CountryViews(); countryViews.Name = countrySearchTextBox.Text; if (countryViews.Name != "") { List <CountryViews> countryViewList = countryManager.GetCountryByName(countryViews.Name); if (countryViewList.Count > 0) { countryViewGridView.DataSource = countryViewList; countryViewGridView.DataBind(); } else { message = "<div class='alert alert-danger' role='alert'>Sorry, we can't find " + countryViews.Name + " </div>"; } } messageLabel.Text = message; Clear(); countryViewGridView.UseAccessibleHeader = true; countryViewGridView.HeaderRow.TableSection = TableRowSection.TableHeader; }
public List <CountryViews> ShowAllCountry() { List <CountryViews> countryViewList = new List <CountryViews>(); SqlConnection connection = new SqlConnection(connectionString); string query = "Select * from CountryViews"; connection.Open(); SqlCommand command = new SqlCommand(query, connection); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { CountryViews countryViews = new CountryViews(); countryViews.Name = reader["Name"].ToString(); countryViews.About = reader["About"].ToString(); countryViews.NoOfCities = Convert.ToInt32(reader["NoOfCities"]); countryViews.NoOfDwellers = Convert.ToInt32(reader["NoOfDwellers"]); countryViewList.Add(countryViews); } connection.Close(); return(countryViewList); }