所以我忙于使用asp.net c#quiz app,用户可以登录并参加测验。测验的价值/问题是从数据库中获取的,它显示并且工作正常,但问题是当所有问题都得到回答时,我有一个按钮,表示&#34;再次进行测验&#34;在哪个我将用户重定向到测验假设要重新加载的起始页面,但它根本没有显示任何内容,(我认为它只是在数据库中循环一次而且它或者我可能是错的)< / p>
这是我的c#代码 页面加载()
MySqlDataAdapter adp = new MySqlDataAdapter("SELECT * FROM question WHERE category_id=" + categoryID, db.getCon());
adp.Fill(ds);
try
{
// teller = ds.Tables[0].Rows[i][0].ToString();
lblQuestion.Text = ds.Tables[0].Rows[i][1].ToString();
rbA.Text = ds.Tables[0].Rows[i][2].ToString();
rbB.Text = ds.Tables[0].Rows[i][3].ToString();
rbC.Text = ds.Tables[0].Rows[i][4].ToString();
rbD.Text = ds.Tables[0].Rows[i][5].ToString();
correctAnswer = ds.Tables[0].Rows[i][6].ToString();
infoQuestion = ds.Tables[0].Rows[i][7].ToString();
}
catch (Exception)
{
}
并点击按钮
private void nextQuestion()
{
i++;
lblQuestion.Text = ds.Tables[0].Rows[i][1].ToString();
rbA.Text = ds.Tables[0].Rows[i][2].ToString();
rbB.Text = ds.Tables[0].Rows[i][3].ToString();
rbC.Text = ds.Tables[0].Rows[i][4].ToString();
rbD.Text = ds.Tables[0].Rows[i][5].ToString();
}
答案 0 :(得分:0)
在Page_Load中设置.Reference
,使其不会超出范围。在测验完成后你没有重置它
在此处添加一些日志记录或弹出消息。像这样吞下异常绝不是一个好主意。
i=0
在nextQuestion()中添加catch (Exception)
{
}
,以便在填写下一个问题时能够发现问题。这样,您只在Page_Load