Hi,
I develop a code for data manipulation i.e (first, next, previous and last record). i try the below mentioned code,
In this, i click next button -- move the next record. i click one more time it doesnt move
same as for previous button.
protected void Page_Load(objec t sender, EventArgs e)
{
SqlConnection con = new SqlConnection() ;
//SqlCommand cmd = new SqlCommand();
con.ConnectionS tring = "Data source=localhos t;initial catalog=northwi nd;integrated security=true";
String cmd = "select * from employees";
//cmd.CommandType = CommandType.Tex t;
//cmd.Connection = con;
//cmd.Connection. Open();
SqlDataAdapter da = new SqlDataAdapter( cmd, con);
DataSet ds = new DataSet();
da.Fill(ds, "employeeinfo") ;
dt = ds.Tables["employeein fo"];
tot = dt.Rows.Count;
Label5.Text = tot.ToString();
fill();
//SqlDataReader dr = cmd.ExecuteRead er(CommandBehav ior.CloseConnec tion);
//Label5.Text= Convert.ToStrin g(dr.FieldCount );
//while (dr.Read())
//{
// TextBox1.Text = dr["employeeid "].ToString();
// TextBox2.Text = dr["firstname"].ToString();
// TextBox3.Text = dr["city"].ToString();
// TextBox4.Text = dr["country"].ToString();
//}
//Label5.Text=dr. RecordsAffected .ToString();
//GridView1.DataS ource = dr;
//GridView1.DataB ind();
//cmd.Dispose();
//dr.Dispose();
}
protected void Button6_Click(o bject sender, EventArgs e)
{
//First record
cur = 0;
fill();
Label5.Text = cur.ToString();
}
protected void Prev_Click(obje ct sender, EventArgs e)
{
//previous record
cur--;
if (cur < 0)
cur = tot - 1;
fill();
Label5.Text = cur.ToString();
}
private void fill()
{
TextBox1.Text = dt.Rows[cur]["employeeid "].ToString();
TextBox2.Text = dt.Rows[cur]["firstname"].ToString();
TextBox3.Text = dt.Rows[cur]["city"].ToString();
TextBox4.Text = dt.Rows[cur]["country"].ToString();
Label5.Text = cur.ToString();
}
protected void Button8_Click(o bject sender, EventArgs e)
{
if (cur < tot - 1)
{
cur = cur + 1;
fill();
}
// //Next record
// cur = cur + 1;
// if (cur > tot-1)
// {
//// cur = 0;
// }
// else
// {
// fill();
// }
// Label5.Text = cur.ToString();
}
protected void Button9_Click(o bject sender, EventArgs e)
{
//Last record
cur = tot - 1;
fill();
Label5.Text = cur.ToString();
}
thanks,
murugavel
I develop a code for data manipulation i.e (first, next, previous and last record). i try the below mentioned code,
In this, i click next button -- move the next record. i click one more time it doesnt move
same as for previous button.
protected void Page_Load(objec t sender, EventArgs e)
{
SqlConnection con = new SqlConnection() ;
//SqlCommand cmd = new SqlCommand();
con.ConnectionS tring = "Data source=localhos t;initial catalog=northwi nd;integrated security=true";
String cmd = "select * from employees";
//cmd.CommandType = CommandType.Tex t;
//cmd.Connection = con;
//cmd.Connection. Open();
SqlDataAdapter da = new SqlDataAdapter( cmd, con);
DataSet ds = new DataSet();
da.Fill(ds, "employeeinfo") ;
dt = ds.Tables["employeein fo"];
tot = dt.Rows.Count;
Label5.Text = tot.ToString();
fill();
//SqlDataReader dr = cmd.ExecuteRead er(CommandBehav ior.CloseConnec tion);
//Label5.Text= Convert.ToStrin g(dr.FieldCount );
//while (dr.Read())
//{
// TextBox1.Text = dr["employeeid "].ToString();
// TextBox2.Text = dr["firstname"].ToString();
// TextBox3.Text = dr["city"].ToString();
// TextBox4.Text = dr["country"].ToString();
//}
//Label5.Text=dr. RecordsAffected .ToString();
//GridView1.DataS ource = dr;
//GridView1.DataB ind();
//cmd.Dispose();
//dr.Dispose();
}
protected void Button6_Click(o bject sender, EventArgs e)
{
//First record
cur = 0;
fill();
Label5.Text = cur.ToString();
}
protected void Prev_Click(obje ct sender, EventArgs e)
{
//previous record
cur--;
if (cur < 0)
cur = tot - 1;
fill();
Label5.Text = cur.ToString();
}
private void fill()
{
TextBox1.Text = dt.Rows[cur]["employeeid "].ToString();
TextBox2.Text = dt.Rows[cur]["firstname"].ToString();
TextBox3.Text = dt.Rows[cur]["city"].ToString();
TextBox4.Text = dt.Rows[cur]["country"].ToString();
Label5.Text = cur.ToString();
}
protected void Button8_Click(o bject sender, EventArgs e)
{
if (cur < tot - 1)
{
cur = cur + 1;
fill();
}
// //Next record
// cur = cur + 1;
// if (cur > tot-1)
// {
//// cur = 0;
// }
// else
// {
// fill();
// }
// Label5.Text = cur.ToString();
}
protected void Button9_Click(o bject sender, EventArgs e)
{
//Last record
cur = tot - 1;
fill();
Label5.Text = cur.ToString();
}
thanks,
murugavel