为什么我的代码永远不会进入我的循环



我正在研究测验程序。

以下代码在Form2_Load方法中。

ctrque[]是全局integer变量。

您能帮助我弄清楚为什么代码不输入while(read.Read())循环?

con.Open();
com.CommandText = "SELECT * FROM questions";
OleDbDataReader read = com.ExecuteReader();
while (read.Read()) { // this is the loop I'm talking about
    if (int.Parse(read["qid1"].ToString()) == que[ctr]) { // where que[] is containing of 30 unique random numbers
        qtnTxt.Text = read["qtn"].ToString(); //For output of the question
        for (int x = 0; x < 4; x++) { //for unique random choices in quiz bee. I have no problem about this.
            ans[x] = ran.Next(2, 6);
            for (int y = x; y >= 0; y--) {
                if (x == y) {
                    continue;
                } else if (ans[x] == ans[y]) {
                    ans[x] = ran.Next(2, 6);
                    y = x;
                }
            }
        }
    //Choices outputs
    aBtn.Text = read.GetString(ans[0]).ToString();
    bBtn.Text = read.GetString(ans[1]).ToString();
    cBtn.Text = read.GetString(ans[2]).ToString();
    dBtn.Text = read.GetString(ans[3]).ToString();
    }
}
ctr++;
read.Close();
com.ExecuteNonQuery();
con.Close();

OleDbDataReader read = com.ExecuteReader();

下方移动com.CommandText = "SELECT * FROM questions";

有答案。我只是在我制作的一些应用程序上尝试了它,这是我的结论。

最新更新