using System;
using System.Data;
using System.Data.OleDb;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class testing : System.Web.UI.Page
{
int num = 0;
static int j=0;
static string[] answer = new string[10];
static int[] s = new int[10];
static Random a = new Random();
protected void Page_Load(object sender, EventArgs e)
{
Random a = new Random();
string connectionString = "Provider = Microsoft.Jet.OleDb.4.0; Data Source=" + MapPath("~/Database1.mdb");
string b = Session["item"].ToString();
string sql = "select *from que_table";
OleDbConnection con = new OleDbConnection(connectionString); con.Open();
OleDbCommand cmd = new OleDbCommand(sql, con);
OleDbDataReader dbReader = cmd.ExecuteReader();
int count = 1;
while (dbReader.Read()) count++;
int i = a.Next(count);//想要取十个完全不同的随机数为什么会这么难???
int c = 0;
while (c < j - 1)
{
int bc = 0;
for (bc = 0; bc <= c; bc++)
if (i == s[bc])
{
i = a.Next(count);
break;
}
if(bc==c)c++;
}
s[num++] = i;
sql = "Select content From que_table where queNo ='" + i.ToString() +
"'and subject='" + b + "'";
cmd = new OleDbCommand(sql, con); string question = Convert.ToString(cmd.ExecuteScalar());
con.Close();
quetxtbox.Text = question;
}
protected void Button2_Click(object sender, EventArgs e)
{
answer[j++] = antxtbox.Text;
antxtbox.Text = "";
if (j == 9)
{
Button2.Enabled = false;
j = 0;
}
} protected void Button1_Click(object sender, EventArgs e)
{
string connectionString = "Provider = Microsoft.Jet.OleDb.4.0; Data Source=" + MapPath("~/Database1.mdb");
string user = Session["user"].ToString();
for (int count = 0; count < 10; count++)
{
string snum = s[count].ToString();
OleDbConnection con = new OleDbConnection(connectionString);
con.Open();
string sql = "Select key From que_table where queNo ='"+snum+"'";//读取参考答案 OleDbCommand cmd = new OleDbCommand(sql, con);
object obj = cmd.ExecuteScalar();
string key = Convert.ToString(obj);
sql = "Select queScore From que_table where queNo ='"+snum+"'";//读取分值
cmd = new OleDbCommand(sql, con);
int score=Convert.ToInt32(cmd.ExecuteScalar());
int y_score;
if (answer[count].Equals(key)) y_score = score;//这句到底错哪了?实在看不出来……
else y_score = 0;
sql = "insert into score_table values('" + user + "','"
+ snum + "','" + answer[count] + "'," + y_score.ToString() + ")";
cmd = new OleDbCommand(sql, con);
cmd.ExecuteNonQuery();
con.Close();
}
}
}
int y_score;
if (answer[count].Equals(key)) y_score = score;//这句到底错哪了?实在看不出来……--------------------------------------------------------------answer[count] 没取到值?
换言之:引用类型的变量在使用前必须实例化。
protected void Button2_Click(object sender, EventArgs e)
{
answer[j++] = antxtbox.Text; antxtbox.Text = "";
if (j == 9)
{
Button2.Enabled = false;
j = 0;
}
}
///你循环的时候确定answer数组中有值?
for (int count = 0; count < 10; count++)
{
if (answer[count].Equals(key)) y_score = score;//这句到底错哪了?实在看不出来……
}