在线考试-求助大神关于ASP.NET项目的问题

问题描述

求助大神关于ASP.NET项目的问题

求助大神,为什么在线考试模块抓取不了数据!
这段代码有问题吗?

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);
}

}

解决方案

if (!IsPostBack)

写反了吧。试试

if (IsPostBack)

解决方案二:

按照楼上的那么改if (!IsPostBack)->if (!IsPostBack),出现如下异常: 求指教啊,感激不尽!

解决方案三:

按照楼上的那么改if (!IsPostBack)->if (!IsPostBack),出现如下异常: 求指教啊,感激不尽!

解决方案四:

=和where之间需要一个空格。

时间: 2024-08-03 05:55:36

在线考试-求助大神关于ASP.NET项目的问题的相关文章

sql server-求助大神一个ASP.NET下增加删除数据的问题,真心请教!

问题描述 求助大神一个ASP.NET下增加删除数据的问题,真心请教! public partial class _Default : System.Web.UI.Page { string constr = "server=192.168.1.113;database=HH;Uid=sa;pwd=000000;"; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Bind(); } }

求助大神,关于ASP.NET在线考试系统中的问题

问题描述 求助大神,为什么在线考试模块不能抓取考试成绩?代码如下:usingSystem;usingSystem.Data;usingSystem.Configuration;usingSystem.Web;usingSystem.Web.Security;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Web.UI.WebControls.WebParts;usingSystem.Web.UI.HtmlControls

java-JavaWeb小白求助!大神老师来帮忙啊!在线等!!!

问题描述 JavaWeb小白求助!大神老师来帮忙啊!在线等!!! JSP页面: <body> <form name="myform" method="post" action="newstypeservlet?op=batchDelete"> <table border="1"> <tr> <th>编号</th> <th>类型名</th&

visual studio-实习生的烦恼,求助大神!

问题描述 实习生的烦恼,求助大神! 利用visual studio 创建website,并用C#语言实现对数据库中店铺和店员的一些信息的查询,并在网站上显示出来.求高人指点啊!!! 解决方案 点我回答右边的采纳,姐姐给你几个现成的程序. 解决方案二: http://www.51aspx.com/code/ZXCJinXiaoCunMS 解决方案三: http://www.jb51.net/codes/311650.html 解决方案四: 嗯,你可以用asp.net mvc做一个网站,这里有个简单

django-Django-cas 单点登录求助大神

问题描述 Django-cas 单点登录求助大神 报错信息:[Errno socket error] [Errno 1] _ssl.c:504: error:14077438:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert internal error Django Setting文件里面已经安装配置配置了,附上setting部分代码: INSTALLED_APPS = ( 'django.contrib.admin' 'django.contri

js手势放大缩小,在线等各位大神开源包

问题描述 js手势放大缩小,在线等各位大神开源包 求救,如下面地址的座位图http://m.dianying.baidu.com/ticket/select?movieId=9486&cinemaId=268&seqNo=1435762200000010108&date=1435680000000&sfrom=newnuomi&from=webapp&sub_channel=nuomi_wap_rukou1&source=nuomi&c=13

算法-求助大神:c语言求最长公共子序列问题

问题描述 求助大神:c语言求最长公共子序列问题 我写的这个能正确求出最长序列元素个数但是输出的最长序列却是乱码,求大神指教.代码如下: #include #include #include #define MAX 101 int Long(char a[],char b[],char result[] ) { int m,n; m=strlen(a); n=strlen(b); int str[MAX][MAX]; int i,j,sum; for(i=0;i<=m;i++) { str[i][

求助大神!!!!windows下的udp协议封装,实现网络通信

问题描述 求助大神!!!!windows下的udp协议封装,实现网络通信 在Qt平台上写的一个程序,是基于udp协议的网络通信,通过在一台电脑上打开两个命令窗口可以实现通信,为什么在两台电脑上就不行了?两台电脑连在同一个路由器下,已经关了防火墙!纠结了2天的问题了,求大神解决!!!!! 解决方案 先ping下看看通不通,本机的防火墙和路由的防火墙是否都关了.路由的防火墙是否禁用了广播.端口号,ip是否正确.程序先在本地双开能运行么?

求助大神,这个matlab程序如何修改才能正确运行?

问题描述 求助大神,这个matlab程序如何修改才能正确运行? function [Zp,Y1p,Y2p,Y3p,Xp,LC1,LC2]=JSPGA(M,N,Pm,T,P) %-------------------------------------------------------------------------- %??JSPGA.m %??流水线型车间作业调度遗传算法 %??GreenSim团队原创作品,转载请注明 %??Email:greensim@163.com %??Green