Click here to Skip to main content
15,908,776 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have written code but not Executing properly if it is possible give me other code

problem is when i click on next button it is showing me next record, program works properly but when I log out and log in directly shows me last record not from start
Question table colums are question_id,teacher_id,teacher_question,teacher_answer

//code is


namespace project_master
{
    public partial class acnj : System.Web.UI.Page
    {
              
        SqlCommand cmd = new SqlCommand();
        public static int i = 0;
          DataTable dt = new DataTable();
        DataRow drr;
        SqlConnection con = new SqlConnection(@"Data Source=.\sqlexpress;Initial Catalog=swatidb;Integrated Security=True;Pooling=False");
         public void Page_Load(object sender, EventArgs e)
        {
            con.Open();
            string s1 = "select student_id from Student where user_name='" + Session["sid"] + "'";
            SqlCommand cmd = new SqlCommand(s1, con);
            SqlDataReader dr;
            dr = cmd.ExecuteReader();
            if (dr.Read())
            {
                Label4_stu_id.Text =dr[0].ToString();//for displaying student_id
                dr.Close();
            }
            SqlDataAdapter da = new SqlDataAdapter("select * from Question where question_id>=1 and question_id<=3", con);
            da.Fill(dt);
            drr = dt.Rows[i];
 
            Label2_tea_que.Text = "Write question below in Textbox  click next to get questoion";
          
        }
         public void next_Click(object sender, System.EventArgs e)
         {
             if (i == (dt.Rows.Count - 1))
             {
                 Response.Write("Last record !");
             }
             else
             {
                 i++;
             }
               Label3_que_id.Text = Convert.ToString(drr[0]);//tlabel for displaying question_id
             Label2_tea_que.Text = Convert.ToString(drr[2]); //label displaying Teacher question
          }
       }   

}
Posted
Updated 22-Mar-14 7:39am
v4
Comments
OriginalGriff 22-Mar-14 12:05pm    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
So what does it do that it shouldn't, or not do that it should?
Use the "Improve question" widget to edit your question and provide better information.

And while you are at it, tidy up that code. Dump the commented out rubbish, reformat it to get the indentation right, and generally make it easy for us to read.
Help us to help you!
swati gapat 22-Mar-14 13:42pm    
now i have updated give reply to question
Krunal Rohit 22-Mar-14 12:12pm    
First, please remove all the unnecessary comments/spaces from the code.
Second, format it properly.
Third, use the proper naming convention for the controls - we can't work out on that to understand what it is.

-KR
swati gapat 22-Mar-14 13:43pm    
now i have updated give reply to question

1 solution

This is the same question as how to write code for next button in online examination and also for previous button[^]. Please edit your original rather than reposting.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900