You are on page 1of 5

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!!");

dr = Cmd.ExecuteReader(); recordcount = ds.Tables[0].Rows.Count; Response.Write("Record Count : " +recordcount);

if (recordcount > 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("There are no records in this category"); } dr.Read();

Con.Close(); Response.Write("Connection is Closed Now!!"); }

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"); }

protected void btnPrevious_Click(object sender, EventArgs e) {

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"); }

protected void btnNext_Click(object sender, EventArgs e) {

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!!"); } }

protected void btnLast_Click(object sender, EventArgs e)

{ 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();

Response.Write("You have reached the last record in this category!!"); }

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(); }

You might also like