How to retrieve all the records from database into textboxes using dataadapter

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • muskan
    New Member
    • Nov 2006
    • 35

    How to retrieve all the records from database into textboxes using dataadapter

    hello,


    I want to fetch all the records from database one by one when I click on next button

    I have written this code for fetching the records from database.
    But it shows only first record.
    What code I have to written so that all the records can be fetch into textboxes.

    SqlDataAdapter da = new SqlDataAdapter( "select * from detail",conn1);
    DataSet ds = new DataSet();

    da.Fill(ds);


    txtname.Text =ds.Tables[0].Rows[0][0].ToString();
    txtroll.Text =ds.Tables[0].Rows[0]["roll no"].ToString();
  • decyclone
    New Member
    • Dec 2006
    • 7

    #2
    Hi,

    For maintaining the index you could keep one variable,
    on 'next' button press, increment it,
    on 'prev' button press, decrement it.
    don't forget to check bounds (less than zero and more than max limit).

    and just update the textbox text with new values by using [index] instead of [0] in your code.

    hope this helps.

    Jay.

    Comment

    • muskan
      New Member
      • Nov 2006
      • 35

      #3
      I have taken the index instead of 0 but it is not showing all the records

      Could u give me hint by writing some code.

      Originally posted by decyclone
      Hi,

      For maintaining the index you could keep one variable,
      on 'next' button press, increment it,
      on 'prev' button press, decrement it.
      don't forget to check bounds (less than zero and more than max limit).

      and just update the textbox text with new values by using [index] instead of [0] in your code.

      hope this helps.

      Jay.

      Comment

      • vinaykeshav
        New Member
        • Dec 2006
        • 25

        #4
        declare an int global..
        private static int i =0;

        at next u increment and at back u decrement it..

        txtname.Text =ds.Tables[0].Rows[i][0].ToString();
        txtroll.Text =ds.Tables[0].Rows[i]["roll no"].ToString();

        this might help u..

        Originally posted by muskan
        I have taken the index instead of 0 but it is not showing all the records

        Could u give me hint by writing some code.

        Comment

        • kenobewan
          Recognized Expert Specialist
          • Dec 2006
          • 4871

          #5
          IMO - you could use an sqldatareader ADO.NET: Retrieve Data from SQL Server

          Hope that this helps.

          Comment

          Working...