C#/Mysql测验只有5个问题
我这里的代码有点问题,希望你能帮助我 我想写一个测验,在表格上显示问题, 您可以通过单击5个回答按钮中的一个来回答这些问题。 这些问题存储在Mysql数据库中 在每个游戏中,玩家必须回答5个问题, 问题来了: 在5个问题之后,它不会进入记分页面 我如何解决这个问题 以下是我的尝试:C#/Mysql测验只有5个问题,c#,mysql,C#,Mysql,我这里的代码有点问题,希望你能帮助我 我想写一个测验,在表格上显示问题, 您可以通过单击5个回答按钮中的一个来回答这些问题。 这些问题存储在Mysql数据库中 在每个游戏中,玩家必须回答5个问题, 问题来了: 在5个问题之后,它不会进入记分页面 我如何解决这个问题 以下是我的尝试: public int richtig; int Counter = 0; string Loesung, AntwortA_value, AntwortB_value, A
public int richtig;
int Counter = 0;
string Loesung, AntwortA_value, AntwortB_value, AntwortC_value, AntwortD_value, AntwortE_value;
string cmdText = "SELECT fragen,A,B,C,D,E,Loesungen from Fragen order by Rand() Limit 1;";
string MyConString = "SERVER=localhost;DATABASE=quiz;UID=xxx;PASSWORD=xxx;";
public Fragen()
{
InitializeComponent();
Questions();
}
private void Antworten_Click(object sender, EventArgs e)
{
if (Counter != 4)
{
Questions();
Counter++;
}
else
{
}
}
private void Questions()
{
if (Counter != 5)
{
using (MySqlConnection connection = new MySqlConnection(MyConString))
{
try
{
MySqlCommand cmd = new MySqlCommand(cmdText, connection);
connection.Open();
MySqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
FragenTitel.Text = (reader[0].ToString());
AntwortA.Text = (reader[1].ToString());
AntwortB.Text = (reader[2].ToString());
AntwortC.Text = (reader[3].ToString());
AntwortD.Text = (reader[4].ToString());
AntwortE.Text = (reader[5].ToString());
Loesung = (reader[6].ToString());
AntwortA_value = (reader[1].ToString());
AntwortB_value = (reader[2].ToString());
AntwortC_value = (reader[3].ToString());
AntwortD_value = (reader[4].ToString());
AntwortE_value = (reader[5].ToString());
}
reader.Close();
connection.Close();
//lblError.Text = "Data Saved";
}
catch (Exception)
{
MessageBox.Show("not entered");
//lblError.Text = ex.Message;
}
}
}
else
{
Auswertungen Aw = new Auswertungen();
Aw.Show();
}
Counter = richtig;
}
#region Antwortbuttons
private void AntwortButtonA_Click(object sender, EventArgs e)
{
if (AntwortA_value == Loesung)
{
MessageBox.Show("Richtig");
Counter++;
richtig++;
Questions();
}
else
{
MessageBox.Show("Falsch");
Counter++;
Questions();
}
}
private void AntwortButtonB_Click(object sender, EventArgs e)
{
if (AntwortB_value == Loesung)
{
MessageBox.Show("Richtig");
Counter++;
richtig++;
Questions();
}
else
{
MessageBox.Show("Falsch");
Counter++;
Questions();
}
}
private void AntwortButtonC_Click(object sender, EventArgs e)
{
if (AntwortB_value == Loesung)
{
MessageBox.Show("Richtig");
Counter++;
richtig++;
Questions();
}
else
{
MessageBox.Show("Falsch");
Counter++;
Questions();
}
}
private void AntwortButtonD_Click(object sender, EventArgs e)
{
if (AntwortD_value == Loesung)
{
MessageBox.Show("Richtig");
Counter++;
richtig++;
Questions();
}
else
{
MessageBox.Show("Falsch");
Counter++;
Questions();
}
}
private void AntwortButtonE_Click(object sender, EventArgs e)
{
if (AntwortE_value == Loesung)
{
MessageBox.Show("Richtig");
Counter++;
richtig++;
Questions();
}
else
{
MessageBox.Show("Falsch");
Counter++;
Questions();
}
#endregion
}
private void Score_uebername()
{
// richtig = Auswertungen.Punktzahl;
}
}
}
问题在于:
if (Counter != 4)
{
Questions();
Counter++;
}
else
{
}
这种代码的和平不会让计数器达到5,这意味着以下条件:
if (Counter != 5)
{
....
}
else <--this condition is never met because Counter never gets to 5
{
Auswertungen Aw = new Auswertungen();
Aw.Show();
}
if(计数器!=5)
{
....
}
否则,还有什么不能做的呢?您是否尝试过使用调试器来确认测试是否正常工作?在回答了5个或6个正确答案后测试是否正常工作?请在发布更多问题之前阅读。我相信你没有正确理解这个平台的用途。如果使用下面定义的问题句柄,它将达到5。