Professional Documents
Culture Documents
Using Using Using Using Using Using Using Using Using Using Using Using Using
Using Using Using Using Using Using Using Using Using Using Using Using Using
System; System.Collections; System.Configuration; System.Data; System.Linq; System.Web; System.Web.Security; System.Web.UI; System.Web.UI.HtmlControls; System.Web.UI.WebControls; System.Web.UI.WebControls.WebParts; System.Xml.Linq; System.Data.OleDb;
namespace NewOne { public partial class _Default : System.Web.UI.Page { OleDbConnection Con; OleDbCommand Cmd; OleDbDataAdapter da; OleDbDataReader dr; DataSet ds; int recordcount = 0; int i; protected void Page_Load(object sender, EventArgs e) { Con = new OleDbConnection("Provider = Microsoft.Jet.OLEDB.4.0;data source = F:\\Nwind.mdb"); Cmd = new OleDbCommand("SELECT * FROM Customers", Con); da = new OleDbDataAdapter(Cmd); ds = new DataSet("Customers"); Con.Open(); this.da.Fill(ds,"Customers"); Response.Write("Connection is Open Now!!");
txtCompanyName.Text = ds.Tables[0].Rows[i]["CompanyName"].ToString(); txtContactName.Text = ds.Tables[0].Rows[i]["ContactName"].ToString(); txtAddress.Text = ds.Tables[0].Rows[i]["Address"].ToString(); txtCity.Text = ds.Tables[0].Rows[i]["City"].ToString(); txtRegion.Text = ds.Tables[0].Rows[i]["Region"].ToString(); txtCountry.Text = ds.Tables[0].Rows[i]["Country"].ToString(); txtPhone.Text = ds.Tables[0].Rows[i]["Phone"].ToString(); } else { Response.Write("There are no records in this category"); } dr.Read();
protected void btnFirst_Click(object sender, EventArgs e) { if (ds.Tables[0].Rows.Count > 0) { i = 0; txtCustomerID.Text = ds.Tables[0].Rows[i]["CustomerID"].ToString(); txtCompanyName.Text = ds.Tables[0].Rows[i]["CompanyName"].ToString(); txtContactName.Text = ds.Tables[0].Rows[i]["ContactName"].ToString(); txtAddress.Text = ds.Tables[0].Rows[i]["Address"].ToString(); txtCity.Text = ds.Tables[0].Rows[i]["City"].ToString(); txtRegion.Text = ds.Tables[0].Rows[i]["Region"].ToString(); txtCountry.Text = ds.Tables[0].Rows[i]["Country"].ToString(); txtPhone.Text = ds.Tables[0].Rows[i]["Phone"].ToString(); } else { Response.Write("You have reached the First record in this Category"); }
if (i == ds.Tables[0].Rows.Count - 1) { i--; txtCustomerID.Text = ds.Tables[0].Rows[i]["CustomerID"].ToString(); txtCompanyName.Text = ds.Tables[0].Rows[i]["CompanyName"].ToString(); txtContactName.Text = ds.Tables[0].Rows[i]["ContactName"].ToString(); txtAddress.Text = ds.Tables[0].Rows[i]["Address"].ToString(); txtCity.Text = ds.Tables[0].Rows[i]["City"].ToString(); txtRegion.Text = ds.Tables[0].Rows[i]["Region"].ToString(); txtCountry.Text = ds.Tables[0].Rows[i]["Country"].ToString(); txtPhone.Text = ds.Tables[0].Rows[i]["Phone"].ToString(); } else { Response.Write("You have reached the begining of the records in this category"); }
if (i < ds.Tables[0].Rows.Count - 1) { i++; txtCustomerID.Text = ds.Tables[0].Rows[i]["CustomerID"].ToString(); txtCompanyName.Text = ds.Tables[0].Rows[i]["CompanyName"].ToString(); txtContactName.Text = ds.Tables[0].Rows[i]["ContactName"].ToString(); txtAddress.Text = ds.Tables[0].Rows[i]["Address"].ToString(); txtCity.Text = ds.Tables[0].Rows[i]["City"].ToString(); txtRegion.Text = ds.Tables[0].Rows[i]["Region"].ToString(); txtCountry.Text = ds.Tables[0].Rows[i]["Country"].ToString(); txtPhone.Text = ds.Tables[0].Rows[i]["Phone"].ToString(); } else { Response.Write("You have reached the end of records in this category!!"); } }
{ i = ds.Tables[0].Rows.Count - 1;
txtCustomerID.Text = ds.Tables[0].Rows[i]["CustomerID"].ToString(); txtCompanyName.Text = ds.Tables[0].Rows[i]["CompanyName"].ToString(); txtContactName.Text = ds.Tables[0].Rows[i]["ContactName"].ToString(); txtAddress.Text = ds.Tables[0].Rows[i]["Address"].ToString(); txtCity.Text = ds.Tables[0].Rows[i]["City"].ToString(); txtRegion.Text = ds.Tables[0].Rows[i]["Region"].ToString(); txtCountry.Text = ds.Tables[0].Rows[i]["Country"].ToString(); txtPhone.Text = ds.Tables[0].Rows[i]["Phone"].ToString();
protected void btnUpdate_Click(object sender, EventArgs e) { Con = new OleDbConnection("Provider = Microsoft.Jet.OLEDB.4.0;data source = F:\\Nwind.mdb"); Cmd = new OleDbCommand("UPDATE record set CompanyName =" + txtCompanyName.Text + "ContactName=" + txtContactName.Text + "Address=" + txtAddress.Text + "City=" + txtCity.Text + "Region=" + txtRegion.Text + "Country=" + txtCountry.Text + "Phone=" + txtPhone.Text + "WHERE CustomerID=" + txtCustomerID.Text + " "); Con.Open(); //Cmd.ExecuteNonQuery(); Con.Close(); }
protected void btnEdit_Click(object sender, EventArgs e) { Con = new OleDbConnection("Provider = Microsoft.Jet.OLEDB.4.0;data source = F:\\Nwind.mdb"); Cmd = new OleDbCommand("EDIT record set CompanyName =" + txtCompanyName.Text + "ContactName =" + txtContactName.Text + "Address=" + txtAddress.Text + "City=" + txtCity.Text + "Region=" + txtRegion.Text + "Country=" + txtCountry.Text + "Phone=" + txtPhone.Text + "WHERE CustomerID=" + txtCustomerID.Text + " "); Con.Open(); //Cmd.ExecuteNonQuery(); Con.Close();
protected void btnDelete_Click(object sender, EventArgs e) { Con = new OleDbConnection("Provider = Microsoft.Jet.OLEDB.4.0;data source = F:\\Nwind.mdb"); Cmd = new OleDbCommand("DELETE FROM Customers WHERE CustomerID = " + txtCustomerID.Text + " "); Con.Open(); //Cmd.ExecuteNonQuery(); Con.Close(); }