62,050
社区成员
发帖
与我相关
我的任务
分享
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
string sqlstr1 = "select Score from Score where StudentID ='" + Session["Ids"] + "' and PaperID='" + DropDownList2.SelectedValue + "'";
SqlDataReader myRead = odb.ExceRead(sqlstr1);//调用公共类中的ExceRead方法创建数据阅读器
myRead.Read();//读取数据
int intcount = Convert.ToInt32(myRead["Score"]);
myRead.Close();//关闭数据阅读器
//Application["d1"] = DropDownList1.SelectedItem;
Session["PaperID"] = DropDownList2.SelectedValue;
Session["PaperName"] = DropDownList2.SelectedItem;
if (intcount < 0)
{
Response.Redirect("Load.aspx");
}
else
{
Response.Write("<script lanuage=javascript>alert('此套题已经答过!请重新选择试题');location='javascript:history.go(-1)'</script>");
}
}
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
string sqlstr1 = "select Score from Score where StudentID ='" + Session["Ids"] + "' and PaperID='" + DropDownList2.SelectedValue + "'";
using(SqlDataReader myRead = odb.ExceRead(sqlstr1))//调用公共类中的ExceRead方法创建数据阅读器
{
myRead.Read();//读取数据
//如果没读取到数据,可以认为题目不存在
int intcount =myRead["Score"] != DBNull.Value ? Convert.ToInt32(myRead["Score"]) : 1;
myRead.Close();//关闭数据阅读器
}
//Application["d1"] = DropDownList1.SelectedItem;
Session["PaperID"] = DropDownList2.SelectedValue;
Session["PaperName"] = DropDownList2.SelectedItem;
if (intcount < 0)
{
Response.Redirect("Load.aspx");
}
else
{
Response.Write("<script lanuage=javascript>alert('此套题已经答过!请重新选择试题');location='javascript:history.go(-1)'</script>");
}
}
myRead.Read();//读取数据
//改成
if(myRead.Read())//加个判断
{
//code
}
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
SqlConnection con = odb.getcon();
con.Open();
string sqlstr1 = "select count(*) from Score where StudentID ='" + Session["Ids"] + "' and PaperID='" + DropDownList2.SelectedValue + "'";
SqlCommand mycom = new SqlCommand(sqlstr1, con);
int intcount = Convert.ToInt32(mycom.ExecuteScalar());
Session["PaperID"] = DropDownList2.SelectedValue;
Session["PaperName"] = DropDownList2.SelectedItem;
if (intcount > 0)
{
Response.Write("<script lanuage=javascript>alert('此套题已经答过!请重新选择试题');location='javascript:history.go(-1)'</script>");
}
else
{
Response.Redirect("Load.aspx");
}
}
基本已解决。。。。