【发布时间】:2016-05-03 11:47:30
【问题描述】:
我刚刚完成了测验的添加部分,即管理员为客人添加问题的部分。
当我点击下一步按钮时,我只看到了我添加的最后一个问题。代码如下:
SqlConnection con = new SqlConnection(@"Data Source=MARIA-PC;Initial Catalog=Account;Integrated Security=True");
con.Open();
SqlCommand cmd = new SqlCommand("SELECT * FROM [dbo].[QuestAdd] WHERE Class = '1'", con);
SqlDataReader reader = null;
reader = cmd.ExecuteReader();
while (reader.Read())
{
textBox2.Text = (reader["Question"].ToString());
textBox3.Text = (reader["R1"].ToString());
textBox4.Text = (reader["R2"].ToString());
textBox5.Text = (reader["R3"].ToString());
textBox6.Text = (reader["R4"].ToString());
if (textBox7.Text == (reader["R_correct"].ToString()))
point = point + 1;
}
con.Close();
我的问题是我不知道为什么我只看到最后一个问题,尽管我有多个问题。
【问题讨论】:
-
next button的代码在哪里? -
一旦 while 循环退出,文本框将包含最后一行的详细信息..
-
您正在阅读的每条记录都被下一条覆盖,最后您将获得最后一条
-
您正在将结果写入循环内的相同文本框,因此它只会存储/显示最后分配的结果。
-
@MXD 这是下一个按钮的代码:D