Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. DataAdapter

DataAdapter

Scheduled Pinned Locked Moved ASP.NET
security
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Murugavel Sadagopan
    wrote on last edited by
    #1

    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(object sender, EventArgs e) { SqlConnection con = new SqlConnection(); //SqlCommand cmd = new SqlCommand(); con.ConnectionString = "Data source=localhost;initial catalog=northwind;integrated security=true"; String cmd = "select * from employees"; //cmd.CommandType = CommandType.Text; //cmd.Connection = con; //cmd.Connection.Open(); SqlDataAdapter da = new SqlDataAdapter(cmd, con); DataSet ds = new DataSet(); da.Fill(ds, "employeeinfo"); dt = ds.Tables["employeeinfo"]; tot = dt.Rows.Count; Label5.Text = tot.ToString(); fill(); //SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); //Label5.Text= Convert.ToString(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.DataSource = dr; //GridView1.DataBind(); //cmd.Dispose(); //dr.Dispose(); } protected void Button6_Click(object sender, EventArgs e) { //First record cur = 0; fill(); Label5.Text = cur.ToString(); } protected void Prev_Click(object 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(object sender, EventArgs e) { if (cur < tot - 1) { cur = cur + 1; fill(); } // //Next record // cur = cur + 1;

    I 1 Reply Last reply
    0
    • M Murugavel Sadagopan

      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(object sender, EventArgs e) { SqlConnection con = new SqlConnection(); //SqlCommand cmd = new SqlCommand(); con.ConnectionString = "Data source=localhost;initial catalog=northwind;integrated security=true"; String cmd = "select * from employees"; //cmd.CommandType = CommandType.Text; //cmd.Connection = con; //cmd.Connection.Open(); SqlDataAdapter da = new SqlDataAdapter(cmd, con); DataSet ds = new DataSet(); da.Fill(ds, "employeeinfo"); dt = ds.Tables["employeeinfo"]; tot = dt.Rows.Count; Label5.Text = tot.ToString(); fill(); //SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); //Label5.Text= Convert.ToString(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.DataSource = dr; //GridView1.DataBind(); //cmd.Dispose(); //dr.Dispose(); } protected void Button6_Click(object sender, EventArgs e) { //First record cur = 0; fill(); Label5.Text = cur.ToString(); } protected void Prev_Click(object 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(object sender, EventArgs e) { if (cur < tot - 1) { cur = cur + 1; fill(); } // //Next record // cur = cur + 1;

      I Offline
      I Offline
      Imran Khan Pathan
      wrote on last edited by
      #2

      Murugavel Sadagopan wrote:

      protected void Page_Load(object sender, EventArgs e) { SqlConnection con = new SqlConnection(); //SqlCommand cmd = new SqlCommand(); con.ConnectionString = "Data source=localhost;initial catalog=northwind;integrated security=true"; String cmd = "select * from employees"; //cmd.CommandType = CommandType.Text; //cmd.Connection = con; //cmd.Connection.Open(); SqlDataAdapter da = new SqlDataAdapter(cmd, con); DataSet ds = new DataSet(); da.Fill(ds, "employeeinfo"); dt = ds.Tables["employeeinfo"]; tot = dt.Rows.Count; Label5.Text = tot.ToString(); fill();

      Put your code in condition.You page load event everytime fill the data on every events. if(!isPostBack) { // Put your code here }

      please don't forget to vote on the post that helped you.

      M 1 Reply Last reply
      0
      • I Imran Khan Pathan

        Murugavel Sadagopan wrote:

        protected void Page_Load(object sender, EventArgs e) { SqlConnection con = new SqlConnection(); //SqlCommand cmd = new SqlCommand(); con.ConnectionString = "Data source=localhost;initial catalog=northwind;integrated security=true"; String cmd = "select * from employees"; //cmd.CommandType = CommandType.Text; //cmd.Connection = con; //cmd.Connection.Open(); SqlDataAdapter da = new SqlDataAdapter(cmd, con); DataSet ds = new DataSet(); da.Fill(ds, "employeeinfo"); dt = ds.Tables["employeeinfo"]; tot = dt.Rows.Count; Label5.Text = tot.ToString(); fill();

        Put your code in condition.You page load event everytime fill the data on every events. if(!isPostBack) { // Put your code here }

        please don't forget to vote on the post that helped you.

        M Offline
        M Offline
        Murugavel Sadagopan
        wrote on last edited by
        #3

        hi imran khan, still i have the same problem. thanks, murugavel

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups