我正在开展一项测验计划。
以下代码采用Form2_Load
方法。
ctr
和que[]
是全局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();
答案 0 :(得分:-1)
将com.CommandText = "SELECT * FROM questions";
移到OleDbDataReader read = com.ExecuteReader();
并且有答案。我只是在我制作的一些应用程序上试过它,这是我的结论。