protected void btnSearchKeyword_Click(object sender, EventArgs e) { if (!txtSearchKeyWord.Text.Equals("")) { string keyword = txtSearchKeyWord.Text; DataSet patients = GetData(keyword); if (patients.Tables.Count > 0) { /**** * BUG: This evaluates to true even when no * data is returned, no table is displayed in this case ****/ GridViewPatients.DataSource = patients; GridViewPatients.DataBind(); lblMsg.Text = "Data found"; lblMsg.ForeColor = Color.Green; txtSearchKeyWord.Focus(); } else { lblMsg.Text = "No data matching keyword '" + keyword + "' was found"; lblMsg.ForeColor = Color.Red; txtSearchKeyWord.Focus(); } } else { lblMsg.Text = "No data was entered"; lblMsg.ForeColor = Color.Red; } }
protected void getAllPatientRecords() { //get all patient records DataSet patients = new DataSet(); using (SqlConnection conn = new SqlConnection(GlobalVariables.CS)) { string query = "select * from patients"; SqlDataAdapter adapter = new SqlDataAdapter(query, conn); //fill the dataset adapter.Fill(patients); //display all patient records if (patients.Tables.Count > 0) { GridViewPatients.DataSource = patients; GridViewPatients.DataBind(); } else { lblMsg.Text = "No data avaialable at the moment!"; lblMsg.ForeColor = Color.Green; } } }