public void UpdateGridView() { SqlConnection conn = new SqlConnection(@"data source = .\sqlexpress; integrated security = true; database = Dentist"); SqlCommand cmd = null; SqlDataReader rdr = null; try { conn.Open(); //Use Stored Procedures cmd = conn.CreateCommand(); cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "Myselectloggedinpatientreservation"; SqlParameter in1 = cmd.Parameters.Add("@patientID", SqlDbType.Int); in1.Direction = ParameterDirection.Input; in1.Value = Convert.ToInt32(Session["patientID"].ToString()); rdr = cmd.ExecuteReader(); GridViewReservation.DataSource = rdr; GridViewReservation.DataBind(); } 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 } }
private void fillReservations() { RezervazijaTerminSelect select = new RezervazijaTerminSelect(); RezervacijaTerminResult result = this.menager.execute(select) as RezervacijaTerminResult; if (result.Success) { GridViewReservation.DataSource = result.Rezervacije.ToList(); GridViewReservation.DataBind(); } }