protected void Button1_Click(object sender, EventArgs e)
{
int count = 0;
// string anw1,anw2,anw3,anw4,anw5,anw6,anw7,anw8;
string [] anw=new string[8];
string[] anwyes=new string [8] ;
int[] score =new int [8];
// string a, b, c, d, e1, f, g, h;
// int t1, t2, t3, t4, t5, t6, t7, t8;
anw[0] = RadioButtonList1.SelectedItem.Value.ToString();
anw[1] = RadioButtonList2.SelectedItem.Value.ToString();
anw[2] = RadioButtonList3.SelectedItem.Value.ToString();
anw[3] = RadioButtonList4.SelectedItem.Value.ToString();
anw[4] = RadioButtonList5.SelectedItem.Value.ToString();
anw[5] = RadioButtonList6.SelectedItem.Value.ToString();
anw[6] = RadioButtonList7.SelectedItem.Value.ToString();
anw[7] = RadioButtonList8.SelectedItem.Value.ToString();
string sql = "SELECT 答案 FROM Que_title where 题目='数据库技术经典习题'";
string sql1 = "SELECT 分值 FROM Que_title where 题目='数据库技术经典习题'";
DataTable dt1 = Class1.GetDsFromSql(sql).Tables[0];
DataTable dt2 = Class1.GetDsFromSql(sql1).Tables[0];
anwyes[0] = dt1.Rows[0]["答案"].ToString();
anwyes[1] = dt1.Rows[1]["答案"].ToString();
anwyes[2] = dt1.Rows[2]["答案"].ToString();
anwyes[3] = dt1.Rows[3]["答案"].ToString();
anwyes[4] = dt1.Rows[4]["答案"].ToString();
anwyes[5] = dt1.Rows[5]["答案"].ToString();
anwyes[6] = dt1.Rows[6]["答案"].ToString();
anwyes[7] = dt1.Rows[7]["答案"].ToString();
score[0] = Convert.ToInt32(dt2.Rows[0]["分值"].ToString());
score[1] = Convert.ToInt32(dt2.Rows[1]["分值"].ToString());
score[2] = Convert.ToInt32(dt2.Rows[2]["分值"].ToString());
score[3] = Convert.ToInt32(dt2.Rows[3]["分值"].ToString());
score[4] = Convert.ToInt32(dt2.Rows[4]["分值"].ToString());
score[5] = Convert.ToInt32(dt2.Rows[5]["分值"].ToString());
score[6] = Convert.ToInt32(dt2.Rows[6]["分值"].ToString());
score[7] = Convert.ToInt32(dt2.Rows[7]["分值"].ToString());
for (int i = 0; i<= 7; i ++)
{
if (anw[i] == anwyes[i])
{
x = "两个数相等";
break;
// count = count + score[i];
}
else
{
x = "两个数不相等";
break;
}
}
// return count;
Label23.Text = x ;
}
为什么这个总是显示两个数不相等,循环中判断有错吗??
4 个解决方案
#1
注意数据库中的数据是不是带空格了
#2
anw anwyes 里面的值打印出来一看就知道了
#3
打印出来是同样的
#4
好了哦,非常感谢jiao006,就是数据库中有空格了
#1
注意数据库中的数据是不是带空格了
#2
anw anwyes 里面的值打印出来一看就知道了
#3
打印出来是同样的
#4
好了哦,非常感谢jiao006,就是数据库中有空格了