Thursday, January 20, 2011

ADO.NET Using C# - Part -6


NAVIGATION/PAGINATION IN C# (WINDOWS FORM)

DATABASE:
NAME = NORTHWIND.
TABLE :
NAME = PRODUCTS.
FIELDS:
productid,productname,unitprice,unitsinstock,categoryid,supplierid.


SqlConnection cn = new SqlConnection("Data Source=.;Initial Catalog=Northwind;Integrated Security=True");
DataSet ds = new DataSet();
private CurrencyManager cm;

public void NAVIGATIONFORM_LOAD(object sender, EventArgs e)
{
SqlDataAdapter da = new SqlDataAdapter("select *from products", cn);
cm = (CurrencyManager)BindingContext[ds.Tables["PRODUCTS"]];
da.Fill(ds, "products");
TextBox1.DataBindings.Add("text", ds.Tables["products"], "productid");
TextBox2.DataBindings.Add("text", ds.Tables["products"], "productname");
TextBox3.DataBindings.Add("text", ds.Tables["products"], "unitprice");
TextBox4.DataBindings.Add("text", ds.Tables["products"], "unitsinstock");
TextBox5.DataBindings.Add("text", ds.Tables["products"], "categoryid");
TextBox6.DataBindings.Add("text", ds.Tables["products"], "supplierid");
dg.DataSource = ds.Tables["products"];
}
private void BTNFIRST_Click(object sender, EventArgs e)
{
cm.Position = 0;
}
private void BTNNEXT_Click(object sender, EventArgs e)
{
cm.Position += 1;
}
private void BTNPREVIOUS_Click(object sender, EventArgs e)
{
cm.Position -= 1;
}
private void BTNLAST_Click(object sender, EventArgs e)
{
cm.Position = cm.Count - 1;
}