恳请大侠帮忙,这问题怎么解决?
protected void ButtonStart_Click(object sender, EventArgs e){
string qnum, timenum, b;
int a, i, j;
//建立连接
SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["connString"]);
//打开连接
conn.Open();
//建立sql1字符串
string sql1 = @"select * from denglubiao where usename='" + Session["usename"] + "'";
//建立数据适配器
SqlDataAdapter sda1 = new SqlDataAdapter(sql1, conn);
//建立数据集
DataSet ds1 = new DataSet();
//填充数据集
sda1.Fill(ds1, "denglubiao");
foreach (DataRow row in ds1.Tables["denglubiao"].Rows)
{
qnum = row["tqnum"].ToString();
timenum = row["ttimenum"].ToString();
}
i = Convert.ToInt32(qnum); //这里的显示这样的错误“使用了未赋值的局部变量qnum”
j = Convert.ToInt32(timenum); //这里的错误和上面一样
Random ro = new Random();
a = ro.Next(i) + j;
b = Convert.ToString(a);
//建立sql字符串
string sql = @"select * from Table1 order by UnitNum asc";
//建立数据适配器
SqlDataAdapter sda = new SqlDataAdapter(sql, conn);
//建立数据集
DataSet ds = new DataSet();
//填充数据集
sda.Fill(ds, "Table1");
foreach (DataRow row in ds.Tables["Table1"].Rows)
{
if (row["QuestionNum"].ToString() == b)
{
Label2.Text = b + ". " + row["Question"].ToString() + "<br>" + row["ChoiceA"].ToString() + "<br>" + row["ChoiceB"].ToString() + "<br>" + row["ChoiceC"].ToString() + "<br>" + row["ChoiceD"].ToString();
}
}
conn.Close();
}
我想把数据库中tqnum和ttimenum字段下的字符串型数据取出来赋值给定义好的变量,就出现了红色字体处的错误,让我很无解,请大侠们帮忙解决下,谢谢了