private void DataLoad() { try { conObj = new SqlConnection(ConfigurationManager.ConnectionStrings["ConCGI"].ConnectionString); } catch (SqlException ex) { Response.Redirect("Error.aspx?Error=" + "We are currently working on...Please try again latter"); DataManager.ErrorLog(ex); } SqlCommand cmdObj = new SqlCommand("select * from Product", conObj); if (conObj.State == ConnectionState.Closed) { conObj.Open(); } SqlDataAdapter adapter = new SqlDataAdapter(cmdObj); DataSet ds = new DataSet(); adapter.Fill(ds, "Product"); DataUpload.DataSource = ds.Tables["Product"]; DataUpload.DataBind(); }
protected void lnlElectronics_Click(object sender, EventArgs e) { LinkButton lbkButton = (LinkButton)sender; string category = lbkButton.Text; try { conObj = new SqlConnection(ConfigurationManager.ConnectionStrings["ConCGI"].ConnectionString); } catch (SqlException ex) { Response.Redirect("Error.aspx?Error=" + "We are currently working on...Please try again latter"); DataManager.ErrorLog(ex); } SqlCommand cmdObj = new SqlCommand("select * from Product where Category=@category or SubCategory=@category", conObj); cmdObj.Parameters.AddWithValue("@category", category); if (conObj.State == ConnectionState.Closed) { conObj.Open(); } SqlDataAdapter adapter = new SqlDataAdapter(cmdObj); DataSet ds = new DataSet(); adapter.Fill(ds, "Product"); DataUpload.DataSource = ds.Tables["Product"]; DataUpload.DataBind(); }
protected void btnSearch_Click(object sender, EventArgs e) { try { conObj = new SqlConnection(ConfigurationManager.ConnectionStrings["ConCGI"].ConnectionString); string search = txtSearch.Text; conObj = new SqlConnection(ConfigurationManager.ConnectionStrings["ConCGI"].ConnectionString); SqlCommand cmdObj = new SqlCommand("select * from Product where Category=@search or SubCategory=@search or ProductName=@search", conObj); cmdObj.Parameters.AddWithValue("@search", search); if (conObj.State == ConnectionState.Closed) { conObj.Open(); } SqlDataAdapter adapter = new SqlDataAdapter(cmdObj); DataSet ds = new DataSet(); adapter.Fill(ds, "Product"); DataUpload.DataSource = ds.Tables["Product"]; DataUpload.DataBind(); } catch (SqlException ex) { Response.Write("Connection Error"); } }