protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { string CS = ConfigurationManager.ConnectionStrings["MainDb"].ConnectionString; using (SqlConnection con = new SqlConnection(CS)) { SqlCommand cmdvw = new SqlCommand("SELECT bak_prog_study.id_prog_study, bak_prog_study.prog_study,bak_prog_study.jenjang FROM bak_prog_study", con); cmdvw.CommandType = System.Data.CommandType.Text; DataTable Table = new DataTable(); Table.Columns.Add("Kode"); Table.Columns.Add("Program Studi"); Table.Columns.Add("Jenjang"); con.Open(); using (SqlDataReader rdr = cmdvw.ExecuteReader()) { if (rdr.HasRows) { while (rdr.Read()) { DataRow datarow = Table.NewRow(); datarow["Kode"] = rdr["id_prog_study"]; datarow["Program Studi"] = rdr["prog_study"]; datarow["Jenjang"] = rdr["jenjang"]; //DateTime DateAwal = Convert.ToDateTime(rdr["open_date"]); //DateTime DateAkhir = Convert.ToDateTime(rdr["close_date"]); //datarow["Tanggal Buka"] = DateAwal.ToString("dd MMMM, yyyy"); //datarow["Tanggal Tutup"] = DateAkhir.ToString("dd MMMM, yyyy"); Table.Rows.Add(datarow); } //Fill Gridview this.GVProdi.DataSource = Table; this.GVProdi.DataBind(); Table.Dispose(); } else { //clear Gridview Table.Rows.Clear(); Table.Clear(); GVProdi.DataSource = Table; GVProdi.DataBind(); } } } } }
protected void load() { string CS = ConfigurationManager.ConnectionStrings["MainDb"].ConnectionString; using (SqlConnection con = new SqlConnection(CS)) { SqlCommand cmdvw = new SqlCommand(" SELECT bak_prog_study.id_prog_study, bak_prog_study.prog_study, keu_masa_bayar.no, keu_masa_bayar.open_date, keu_masa_bayar.close_date " + " FROM bak_prog_study INNER JOIN " + " keu_masa_bayar ON bak_prog_study.id_prog_study = keu_masa_bayar.id_prog_study", con); cmdvw.CommandType = System.Data.CommandType.Text; DataTable Table = new DataTable(); Table.Columns.Add("Kode"); Table.Columns.Add("Program Studi"); Table.Columns.Add("Tanggal Buka"); Table.Columns.Add("Tanggal Tutup"); con.Open(); using (SqlDataReader rdr = cmdvw.ExecuteReader()) { if (rdr.HasRows) { while (rdr.Read()) { DataRow datarow = Table.NewRow(); datarow["Kode"] = rdr["id_prog_study"]; datarow["Program Studi"] = rdr["prog_study"]; DateTime DateAwal = Convert.ToDateTime(rdr["open_date"]); DateTime DateAkhir = Convert.ToDateTime(rdr["close_date"]); datarow["Tanggal Buka"] = DateAwal.ToString("dd MMMM, yyyy"); datarow["Tanggal Tutup"] = DateAkhir.ToString("dd MMMM, yyyy"); Table.Rows.Add(datarow); } //Fill Gridview this.GVProdi.DataSource = Table; this.GVProdi.DataBind(); Table.Dispose(); } else { //clear Gridview Table.Rows.Clear(); Table.Clear(); GVProdi.DataSource = Table; GVProdi.DataBind(); } } } }