protected void BtnLoadData_Click(object sender, EventArgs e) { if (Cache["Data"] == null) { using (SqlConnection con = new SqlConnection(connectionString)) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM ProductInventory", con); DataSet ds = new DataSet(); da.Fill(ds); Cache["Data"] = ds; Gvw_Products.DataSource = ds; Gvw_Products.DataBind(); } LblMessage.Text = "Data loaded from Database"; } else { Gvw_Products.DataSource = (DataSet)Cache["Data"]; Gvw_Products.DataBind(); LblMessage.Text = "Data loaded from Cache"; } }
protected void Page_Load(object sender, EventArgs e) { string connectionString = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString; using (SqlConnection con = new SqlConnection(connectionString)) { SqlCommand cmd = new SqlCommand(); cmd.CommandText = "SELECT * FROM ProductInventory; SELECT* FROM ProductCategories"; cmd.Connection = con; con.Open(); using (SqlDataReader reader = cmd.ExecuteReader()) { Gvw_Products.DataSource = reader; Gvw_Products.DataBind(); while (reader.NextResult()) { Gvw_ProductCategories.DataSource = reader; Gvw_ProductCategories.DataBind(); } } } }