using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Data.OleDb; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls;
namespace Idea { public class buy : System.Web.UI.Page { //private int index; protected System.Data.DataSet ds; protected System.Data.OleDb.OleDbDataAdapter com; protected System.Data.OleDb.OleDbConnection con; protected System.Data.OleDb.OleDbDataAdapter UpdateCom; public bool IsOpen; public string location; protected System.Web.UI.WebControls.DropDownList DropDownList1; protected System.Web.UI.WebControls.Button Button1; protected System.Web.UI.WebControls.Label LblError; protected System.Web.UI.WebControls.Label Lbl1; protected System.Web.UI.WebControls.CheckBox cb1; protected System.Web.UI.WebControls.Label Lbl2; protected System.Web.UI.WebControls.Label Lbl3; protected System.Web.UI.WebControls.CheckBox cb2; protected System.Web.UI.WebControls.CheckBox cb3; protected System.Web.UI.WebControls.Button BtnShowData; protected System.Web.UI.WebControls.Label LblItem; protected System.Web.UI.WebControls.RadioButtonList rblItem; protected System.Web.UI.WebControls.Label Label1; private void Page_Load(object sender, System.EventArgs e) { //index=1; this.rblItem.Items.Clear(); setConnection(); }
#region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); } /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.Button1.Click += new System.EventHandler(this.Button1_Click); this.BtnShowData.Click += new System.EventHandler(this.BtnShowData_Click); this.Load += new System.EventHandler(this.Page_Load);
} #endregion
private void Button1_Click(object sender, System.EventArgs e) { Label1.Text = DropDownList1.SelectedItem.ToString(); fillDDLI(); } void setConnection() { this.location="/../../n/i.mdb"; con
= new System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OL
EDB.4.0;Data source=" + this.location); } void openConnection() { if (!(this.IsOpen)) { this.con.Open(); IsOpen = true; } }
void closeConnection() { if (this.IsOpen) { this.con.Close(); IsOpen = false; } } void fillDDLI() { try { this.openConnection(); OleDbDataReader dr; OleDbCommand cmd = new OleDbCommand("select item from where cat=@cat"); cmd.Connection = con; cmd.Parameters.Add("@cat", this.Label1.Text); dr = cmd.ExecuteReader(); while (dr.Read()) { rblItem.Items.Add(dr["item"].ToString()); } this.closeConnection(); } catch (Exception ex) { this.LblError.Text=ex.ToString(); } } private void fillLabel(){ try { this.openConnection(); OleDbDataReader dr; OleDbCommand cmd = new OleDbCommand("select * from [product] where item=@item"); cmd.Connection = con; cmd.Parameters.Add("@item", this.rblItem.SelectedItem.ToString()); this.LblError.Text=this.rblItem.Sele ctedItem.ToString(); dr = cmd.ExecuteReader(); while (dr.Read()) { this.Lbl1.Text
= "name: "+dr["item"].ToString()+" price:
"+dr["price"].ToString()+" salePrice: "+dr["salePrice"].ToString(); } this.closeConnection(); } catch (Exception ex) { this.LblError.Text=ex.ToString(); } } private void BtnShowData_Click(object sender, System.EventArgs e) { try { this.Lbl1.Text=rblItem.Selecte dItem.Text; } catch (Exception ex) { this.LblError.Text=ex.ToString (); } } } } |