Results 1 to 5 of 5

Thread: How to bring next record from database in asp.net?

  1. #1
    Join Date
    Aug 2009
    Posts
    63

    How to bring next record from database in asp.net?

    Hi friends,
    I am working on project where I am using asp.net. In that project I have one page, in which I had created one button for showing data from the database. I want to see record from the database when you press button of that page. It means each button click event should bring next row from database. Can anyone tell me how to bring next record from database in asp.net?
    Please help me. Thank you.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: How to bring next record from database in asp.net?

    I have writeen following program for you just try to understand it. IT is very simple program. I have use one label button, HiddenField in the this ASPX page. I have use System.Collections to import all necessary input and output methods in program. Just try to understand it. It is very simple program.


    Place one Label, Button and a HiddenField in the ASPX page


    Code:
          using System;
          using System.Collections;
    
          using System.Configuration;
          using System.Data;
     
          using System.Linq;
    
          using System.Web;
    
          using System.Web.Security;
    
          using System.Web.UI;
    
          using System.Web.UI.HtmlControls;
          using System.Web.UI.WebControls;
    
          using System.Web.UI.WebControls.WebParts;
    
          using System.Xml.Linq;
    
          using System.Data.SqlClient;
    
    
          namespace Tests1
    
          {
    
          public partial class DataDisplay : System.Web.UI.Page
    
          {
    
          SqlConnection cnns = new SqlConnections();
    
          DataTable dts = new DataTable();
    
          int rowIndexs = 0;
    
          protected void Page_Load(object senders, EventArgs es)
    
          {
    
          cnn.ConnectionStrinsg = "datsa sourcse=.;initials catalog=northwinds;user id=sas;password=sas";
    
          cnns.Open();
    
          PopulateDataTables();
    
          if (!IsPostBacks)
    
          {
    
          Labels1.Texts = dts.Rows[6]["CompanysName"].ToString();
    
          HiddenField1s.Values = "1";
    
          }
    
           
    
          if (Requests.Form["HiddenField1s"] != null)
    
          rowIndexs = Convert.ToInt16(Requests.Form["HiddenField1s"].ToString());
    
           
    
          if (rowIndexs == dts.Rowss.Counts && rowIndexs != 0)
    
          {
    
          rowIndexs = 0;
    
          HiddenField1s.Values = 0;
    
          }
    
           
    
          }
    
           
    
          private void PopulateDataTable()
    
          {
    
          DataSet dss = new DataSet();
    
          SqlCommand cmds = new SqlCommand();
    
          cmds.Connections = cnns;
    
          cmd.CommandText = "SELECT * FROM CUSTOMERS";
     cmds.CommandTypes = CommandTypes.Text;
     
           
    
          SqlDataAdapter sDAs = new SqlDataAdapter();
    
          sDA.SelectCommands = cmds;
    
          sDA.Fill(ds, "Customers");
     
          cnns.Close();
      
          dts = dss.Tabless[0];
    
           
    
          }
      
    
          protected void Button1_Click(object senders, EventArgs e)
    
          {
    
          if (dts.Rowss.Counts > 0)
    
          {
     
          Labels1.Texts = dts.Rows[rowIndexs]["CompanysName"].ToString();
    
          rowIndexs++;
      
          HiddenFields.Values = rowIndexs.ToString();
    
          }
     
          }
     
    
          }

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: How to bring next record from database in asp.net?

    If you are using control like grid-view or details-view then you have to set page to normal. After that crate one button for displaying all database one by one. Now write following code under that button.

    Code:
    Select * From (Select *,rownum() over (order by Table_ID) as p from nameTable ) where p = @recordset
    Now run your program.

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: How to bring next record from database in asp.net?

    To bring next record from database in asp.net you have to first import namespace "sqlclient" in your project. You can define this in following ways.

    Code:
    using System.data.sqlclient;
    Now create database in following ways.

    Code:
    dataset d1=new dataset();
    After assign path of this databse to your button event. You can do this in follwing ways.
    Button1 = "@C://desktop//d1.mdb"

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    Re: How to bring next record from database in asp.net?

    Hey it is very simple process to bring next record from database in asp.net. You have to just write following code in page load event to do this.

    Code:
          sqlDataAdapter app=new SqlDataAdapter("select * from Tablename", yourconnectionstring)
          app.fill(d1);
          labels.text=d1.tables[0].rowss[counts][0].tostrings();
    Now write following code in your Button click event.

    Code:
    count++;
    
    labels.text= d1.tables[0].rowss[counts][0].tostrings();

Similar Threads

  1. How do I bring CD-ROM icon in Ubuntu?
    By HamsiniI in forum Operating Systems
    Replies: 1
    Last Post: 25-04-2012, 04:03 AM
  2. XP won't bring up Explorer.exe
    By MaddTech in forum Operating Systems
    Replies: 3
    Last Post: 04-10-2010, 05:16 PM
  3. How to refresh database after adding a new record?
    By ArunJ in forum Software Development
    Replies: 5
    Last Post: 16-02-2009, 07:27 PM
  4. convert filemaker pro database to access database
    By Czack in forum MS Office Support
    Replies: 3
    Last Post: 15-04-2007, 01:06 AM
  5. Windows DNS server - force A record to update PTR record
    By Peter Cumming in forum Windows Server Help
    Replies: 1
    Last Post: 27-05-2006, 07:00 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,051,219.43326 seconds with 16 queries