protected void BindPage() { if (Session["LabId"] != null) { DataSet dsbindpage = new DataSet(); dsbindpage = operation.BindNewOrderPage(Session["LabId"].ToString()); if (dsbindpage != null) { DropDownListPatient.DataSource = dsbindpage.Tables[0]; DropDownListPatient.DataTextField = "PatientName"; DropDownListPatient.DataValueField = "PatientID"; DropDownListPatient.DataBind(); DropDownListPatient.Items.Insert(0, new ListItem("Select Patient", "0")); DropDownListDoctor.DataSource = dsbindpage.Tables[1]; DropDownListDoctor.DataTextField = "NAME"; DropDownListDoctor.DataValueField = "NAME"; DropDownListDoctor.DataBind(); DropDownListDoctor.Items.Insert(0, new ListItem("Self", "Self")); RepeaterTest.DataSource = dsbindpage.Tables[2]; RepeaterTest.DataBind(); DropDownListTestCenter.DataSource = dsbindpage.Tables[3]; DropDownListTestCenter.DataTextField = "NAME"; DropDownListTestCenter.DataValueField = "NAME"; DropDownListTestCenter.DataBind(); DropDownListTestCenter.Items.Insert(0, new ListItem("Reffered To", "")); } } }
public void UpdateGridView() { SqlConnection conn = new SqlConnection(@"data source = .\sqlexpress; integrated security = true; database = Patient_dentist;"); SqlDataAdapter da = null; DataSet ds = null; //collection of tables (Used instead of a datareader) DataTable dt = null; // data tables inside the data set string sqlsel = "SELECT * from Reservation"; try { //conn.Open(); SqlDataAdapter opens the connection itself da = new SqlDataAdapter(); // the new makes a new object da.SelectCommand = new SqlCommand(sqlsel, conn); ds = new DataSet(); da.Fill(ds, "MyReservations"); // fills the dataset dt = ds.Tables["MyReservations"]; // we take the information from the dataset and inputs in the table GridViewReservations.DataSource = dt; GridViewReservations.DataBind(); DropDownListPatient.DataSource = dt; DropDownListPatient.DataTextField = "ID_patient"; DropDownListPatient.DataValueField = "ID_patient"; DropDownListPatient.DataBind(); DropDownListPatient.Items.Insert(0, "Select a patient"); DropDownDate.DataSource = dt; DropDownDate.DataTextField = "Date"; DropDownDate.DataValueField = "Date"; DropDownDate.DataBind(); DropDownDate.Items.Insert(0, "Select a date"); } catch (Exception ex) { LabelMessage.Text = ex.Message; } finally { conn.Close(); //The SqlDataAdaptor closes connection by itself; but if something goes wrong, the DataAdaptor can not close the connection } }