protected void Button1_Click(object sender, EventArgs e) { myCollection.Clear(); string conStr = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString; SqlConnection conn = new SqlConnection(conStr); string query = " select * from ProductDetails where Product_Price between " + TextBox1.Text + " and " + TextBox2.Text + " "; SqlCommand cmd = new SqlCommand(query, conn); try { conn.Open(); SqlDataReader reader = cmd.ExecuteReader(); imgArray obj; while (reader.Read()) { obj = new imgArray(); obj.Product_ID = reader["Product_ID"].ToString(); obj.Product_Name = reader["Product_Name"].ToString(); obj.Product_Picture = reader["Product_Picture"].ToString(); obj.Product_Price = reader["Product_Price"].ToString(); obj.Category_ID = reader["Category_ID"].ToString(); myCollection.Add(obj); } } catch (Exception exc) { Response.Write(exc.ToString()); } finally { conn.Close(); } }
private void image() { string conStr = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString; SqlConnection conn = new SqlConnection(conStr); string query = " select * from ProductDetails "; SqlCommand cmd = new SqlCommand(query, conn); try { conn.Open(); SqlDataReader reader = cmd.ExecuteReader(); imgArray obj; while (reader.Read()) { obj = new imgArray(); obj.Product_ID = reader["Product_ID"].ToString(); obj.Product_Name = reader["Product_Name"].ToString(); obj.Product_Picture = reader["Product_Picture"].ToString(); obj.Product_Price = reader["Product_Price"].ToString(); obj.Category_ID = reader["Category_ID"].ToString(); myCollection.Add(obj); } } catch (Exception exc) { Response.Write(exc.ToString()); } finally { conn.Close(); } }
protected void SelectFromCategory() { if (DropDownListProductCategory1.SelectedValue != "0") { string conStr = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString; SqlConnection conn = new SqlConnection(conStr); string query = " select * from ProductDetails where Category_ID=" + DropDownListProductCategory1.SelectedValue + ""; SqlCommand cmd = new SqlCommand(query, conn); try { conn.Open(); SqlDataReader reader = cmd.ExecuteReader(); imgArray obj; while (reader.Read()) { obj = new imgArray(); obj.Product_ID = reader["Product_ID"].ToString(); obj.Product_Name = reader["Product_Name"].ToString(); obj.Product_Picture = reader["Product_Picture"].ToString(); obj.Product_Price = reader["Product_Price"].ToString(); obj.Category_ID = reader["Category_ID"].ToString(); myCollection.Add(obj); } } catch (Exception exc) { Response.Write(exc.ToString()); } finally { conn.Close(); } } else { this.image(); } }