Wrox Programmer Forums
BOOK: Beginning ASP.NET 2.0 and Databases
This is the forum to discuss the Wrox book Beginning ASP.NET 2.0 and Databases by John Kauffman, Bradley Millington; ISBN: 9780471781349
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 2.0 and Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old December 27th, 2009, 02:19 PM
Registered User
Join Date: Oct 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to ritesh7 Send a message via Yahoo to ritesh7
Red face Moving to Next Record Help Required


I am developing a website which has feature for online exam. I have 4 radio buttons for 4 options, 1 label for question and next and previous button. When the page is loaded it display the question and 4 answers. When I click on next or previous buttons. How to move to next or previous record in database with datareader or datatable till the last record. I am pasting the code below. It is in ASP.net with C# and SQL Server 2005 Please help me
public partial class Exam : System.Web.UI.Page
    SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\RiTech.mdf;Integrated Security=True;User Instance=True");

    public DataTable getData()
        SqlCommand cmd = new SqlCommand("Select * from Exam",con);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataTable dt = new DataTable();
        return dt;
    protected void Page_Load(object sender, EventArgs e)
        DataTable dt = getData();
        lblQuestion.Text = dt.Rows[0]["Question"].ToString();
        int count = 0;
        Session ["dt"]=dt;
        Session["count"] = count;
    protected void btnNext_Click(object sender, EventArgs e)
        if (Session["dt"] != null)
            DataTable dt = (DataTable)Session["dt"];
            int count = (int)Session["count"];
            count = count + 1;
            lblQuestion.Text = dt.Rows[count]["Question"].ToString();  


Last edited by ritesh7; December 27th, 2009 at 02:25 PM.. Reason: code

Similar Threads
Thread Thread Starter Forum Replies Last Post
Find Last Record and Add new keyed record causualuser Access VBA 3 February 9th, 2009 08:24 AM
clicking through from record to record on form mat41 Access 3 January 9th, 2009 08:26 AM
how to add new record as first record in dataset hunzian78@yahoo.com ASP.NET 1.0 and 1.1 Professional 4 April 21st, 2006 05:23 AM
Record locking - user needs the next queued record cbtoolkit SQL Server 2000 0 December 6th, 2004 08:29 AM
Sub record not associating with Main record Ron V Access 1 August 31st, 2004 09:21 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.