大神们,真心求助啊!为什么不能抓取成绩数据!!真心求教

why_1001 2015-05-21 07:43:18
求助大神,不知道为什么不能抓取数据!楼主小白,真心求教!


这是test.aspx.cs代码:

using System;
using System.Data;
using System.Configuration;
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;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page
{

private RadioButton[] testBtn1 = new RadioButton[10];
private RadioButton[] testBtn2 = new RadioButton[10];
private RadioButton[] testBtn3 = new RadioButton[10];
private RadioButton[] testBtn4 = new RadioButton[10];
private static int[] rightAns = new int[10];
private int score = 0;

public void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("server=WANGSNOW;database=TestOnline;user id=sa;pwd=root");
con.Open();
SqlCommand cmd = new SqlCommand("select max(id) from XZ_test", con);
int maxTestID = (int)cmd.ExecuteScalar();
int[] testIDs = new int[10];
Random rand = new Random();
String testContent = "";
String ans1 = "";
String ans2 = "";
String ans3 = "";
String ans4 = "";
String testID = "";
for (int i = 0; i < 10; i++)
{
int j = rand.Next(1, maxTestID);
int k = 0;
cmd = new SqlCommand("select id from XZ_test where id=" + j, con);
while (cmd.ExecuteScalar() == null)
{
j = rand.Next(1, maxTestID);
cmd = new SqlCommand("select id from XZ_test where id=" + j, con);
}
while (k <= i)
{
cmd = new SqlCommand("select id from XZ_test where id=" + j, con);
if (j == testIDs[k] || cmd.ExecuteScalar()==null)
{
j = rand.Next(1,maxTestID);
k = 0;
}
else
{
k++;
}
}
Literal l = new Literal();
Literal l1 = new Literal();
cmd = new SqlCommand("select testContent from XZ_test where id=" + j, con);
testContent = (String)cmd.ExecuteScalar();
cmd = new SqlCommand("select testAns1 from XZ_test where id=" + j, con);
ans1 = (String)cmd.ExecuteScalar();
cmd = new SqlCommand("select testAns2 from XZ_test where id=" + j, con);
ans2 = (String)cmd.ExecuteScalar();
cmd = new SqlCommand("select testAns3 from XZ_test where id=" + j, con);
ans3 = (String)cmd.ExecuteScalar();
cmd = new SqlCommand("select testAns4 from XZ_test where id=" + j, con);
ans4 = (String)cmd.ExecuteScalar();


l.Text = i + 1 + "." + testContent + "<br>";
testBtn1[i] = new RadioButton();
testBtn2[i] = new RadioButton();
testBtn3[i] = new RadioButton();
testBtn4[i] = new RadioButton();
testBtn1[i].GroupName = "g" + i;
testBtn1[i].Text = "A、" + ans1 + "  ";
testBtn1[i].ID = "testBtn1" + i;
testBtn2[i] = new RadioButton();
testBtn2[i].GroupName = "g" + i;
testBtn2[i].Text = "B、" + ans2 + "  ";
testBtn2[i].ID = "testBtn2" + i;
testBtn3[i] = new RadioButton();
testBtn3[i].GroupName = "g" + i;
testBtn3[i].Text = "C、" + ans3 + "  ";
testBtn3[i].ID = "testBtn3" + i;
testBtn4[i] = new RadioButton();
testBtn4[i].GroupName = "g" + i;
testBtn4[i].Text = "D、" + ans4 + "  ";
testBtn4[i].ID = "testBtn4" + i;
Panel1.Controls.Add(l);
Panel1.Controls.Add(testBtn1[i]);
Panel1.Controls.Add(testBtn2[i]);
Panel1.Controls.Add(testBtn3[i]);
Panel1.Controls.Add(testBtn4[i]);
l1.Text = "<br><br>";
Panel1.Controls.Add(l1);
testIDs[i] = j;
}
if (!IsPostBack)
{
for (int i = 0; i < 10; i++)
{
cmd = new SqlCommand("select rightAns from XZ_test where id=" + testIDs[i], con);
rightAns[i] = (int)cmd.ExecuteScalar();
}
}
Button b = new Button();
b.Text = "提交";
b.Click += new System.EventHandler(this.b_click);
Literal lc = new Literal();
Literal lc1 = new Literal();
lc.Text = "<center>";
lc1.Text = "</center>";
Panel1.Controls.Add(lc);
Panel1.Controls.Add(b);
Panel1.Controls.Add(lc1);
con.Close();
}

public void b_click(object sender, EventArgs e)
{
for (int i = 0; i < 10; i++)
{
if (testBtn1[i].Checked)
{
if (rightAns[i] == 1)
{
score += 5;
}
}
else if (testBtn2[i].Checked)
{
if (rightAns[i] == 2)
{
score += 5;
}
}
else if (testBtn3[i].Checked)
{
if (rightAns[i] == 3)
{
score += 5;
}
}
else if(testBtn4[i].Checked)
{
if (rightAns[i] == 4)
{
score += 5;
}
}
}
Response.Redirect("result.aspx?score=" + score);
}
}

这是result.aspx.cs代码

using System;
using System.Data;
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;
using System.Configuration;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
String str = Request.QueryString["score"];
SqlConnection con = new SqlConnection("server=WANGSNOW;database=TestOnline;user id=sa;pwd=root");
con.Open();
//SqlCommand cmd = new SqlCommand("insert score set stuID=" + Session["stuID"] + "", con);
//cmd = new SqlCommand("update score set stuID=" + Session["stuID"] + "", con);
SqlCommand cmd = new SqlCommand("update score set XZ_score ='" + str + "'where stuID =" + Session["stuID"] + "", con);
//where stuId='"+考号+"'考号为从登陆界面获取的值
cmd.ExecuteNonQuery();
con.Close();
Response.Write("你的选择题考试成绩是" + str + "分");
}

protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("test1.aspx?");
}
}







...全文
138 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
i疾风 2015-05-22
  • 打赏
  • 举报
回复
哈哈哈,笑死了,你还发了两遍!那我岂不是可以来这边混分。话说你这个真能正常执行?result页面
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        String str = Request.QueryString["score"];
要把default改成result。这个应该shi系统生成的吧? 根据指出这个问题的仁兄提醒,我在想你调试的时候不会直接进的就是result界面把?起码你要从default界面跳转过来才行啊,不然哪里来的接收数据一说
why_1001 2015-05-21
  • 打赏
  • 举报
回复
嗯,好的我试一下,不知道是不是这两个文件出错!
wind_cloud2011 2015-05-21
  • 打赏
  • 举报
回复
学会单步调试,在某行设个断点 ,运行后看每行的变量取得值 ,这样就容易找出问题了
why_1001 2015-05-21
  • 打赏
  • 举报
回复
主要我是特菜的菜鸟,具体不知道哪里出错了!对不住了!
skyandcode 2015-05-21
  • 打赏
  • 举报
回复
你应该先整理好问题,再来提问。 发一大堆代码,对不对人家都要看,太浪费时间了。
  • 打赏
  • 举报
回复
太乱了,没心思看……
why_1001 2015-05-21
  • 打赏
  • 举报
回复
很是着急,求助各位大神们,万分感谢!

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧