Thank you

Hi,
I am Asha Bhatt

I have created one table (Question) , which contain 500 of row and 6 column.
column name are QusID , Question , Option1 ,Option2 , Option3 , option4 .

and in asp.net i have one button and one lable .
when i click on the button
then my query

protected void NextQuestionButton_Click(object sender, EventArgs e)
    {
  SqlConnection con = new SqlConnection(scon);
        con.Open();
        cmd = new SqlCommand("select Question from Questions ", con);
        readqus = cmd.ExecuteReader();
        
        while (readqus.Read())
        {
            
           QuestionLabel.Text = readqus[0].ToString();
            }
             readqus.Close();
        con.Close();
}

here i m getting total row of a column , but i want only 1st row by clicking 1st on the button
and when i will click 2nd time on the button then 2 row should be display like the till 100.

how can i do it please help me.

Thank you.

Recommended Answers

All 2 Replies

1) You must keep one variable or property which will store current id being stored
currquesID=1;
2) I am assuming that your question ID is numeric.
3) in nextquestion button code find minmum question number which is greater than cuRRquestID
4) load data with the found next question no.
5) same code you may write for previous. just fin max instead of min.
6) following code may have syntax error, correct the code whereever applicable

protected void NextQuestionButton_Click(object sender, EventArgs e)
{
  SqlConnection con = new SqlConnection(scon);
        con.Open();
        
''find next number 
		nextnumber =  new SqlCommand("select min(questionid) from Questions where questionid>" & currequesID, con);
		
        cmd = new SqlCommand("select Question from Questions where questionid =" & nextnumber, con);
        readqus = cmd.ExecuteReader();
			        
        while (readqus.Read())
        {
            
           QuestionLabel.Text = readqus[0].ToString();
           	exit;
            }
             readqus.Close();
        con.Close();
        
        currquesid=nextnumber;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.