| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 595 人关注过本帖
标题:无语的错误!特急!
只看楼主 加入收藏
雪雨星风
Rank: 1
来 自:北京
等 级:新手上路
威 望:1
帖 子:566
专家分:0
注 册:2007-10-11
结帖率:100%
收藏
 问题点数:0 回复次数:1 
无语的错误!特急!
protected void Button1_Click(object sender, EventArgs e)
    {
        OleDbConnection myconn = DB.CreateDB();
        myconn.Open();
        OleDbCommand mycomm = new OleDbCommand("select * from jieguo where [user_name] = '" + Session["name"].ToString() + "'", myconn);  //验证是否已经考试过
        int number = Convert.ToInt32(mycomm.ExecuteScalar());
        if (number > 0)
        {            //若考试过就用这次的答案更新以前的答案
            try
            {
                OleDbConnection myconnection = DB.CreateDB();
                myconnection.Open();
                for (int i = 0; i < this.DataList1.Items.Count; i++)
                {
                    Label l = (Label)this.DataList1.Items[i].FindControl("Lb");
                    TextBox tx = (TextBox)this.DataList1.Items[i].FindControl("Txt");
                    OleDbCommand mycommand = new OleDbCommand("update jieguo set zy_ID = " + Convert.ToInt32(l.Text) + ",[user_name] = '" + Session["name"].ToString() + "',body = '" + tx.Text + "',[time] = '" + DateTime.Now + "'", myconnection);
                    int num = mycommand.ExecuteNonQuery();
                }
                Response.Write("<script language=javascript>window.alert('恭喜你交卷成功!');window.location('login.aspx')</script>");
                myconnection.Close();
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
        }
        else
        {        //若没考试过就往数据库里插入答案
            try
            {
                OleDbConnection myconnection = DB.CreateDB();
                myconnection.Open();
                for (int i = 0; i < this.DataList1.Items.Count; i++)
                {
                    Label la = (Label)this.DataList1.Items[i].FindControl("Lb");
                    TextBox tx = (TextBox)this.DataList1.Items[i].FindControl("Txt");
                    OleDbCommand mycommand = new OleDbCommand("insert into jieguo (zy_ID,[user_name],body,[time]) values (" + Convert.ToInt32(la.Text) + ",'" + Session["name"].ToString() + "','" + tx.Text + "','" + DateTime.Now + "')", myconnection);
                    int num = mycommand.ExecuteNonQuery();
                }
                Response.Write("<script language=javascript>window.alert('恭喜你交卷成功!');window.location('login.aspx')</script>");
                myconnection.Close();
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
        }        
    }


//////////////////////////////////////////////////////////////////////////
//错误信息:(在数据库中查不到数据时)
语法错误 (操作符丢失) 在查询表达式 ''protected void Button1_Click(object sender, EventArgs e) { OleDbConnection myconn = DB.CreateDB(); myconn.Open(); OleDbCommand mycomm = new OleDbCommand("select * from jieguo where [user_name] = '" + Session["name"].ToStri' 中。
//////////////////////////////////////////////////////////////////////////
//错误信息:(在数据库中查到数据时)
不提示错误,但是数据库中有多少条数据就被更新多少条,并且更新的结果都是最后一题的答案
搜索更多相关主题的帖子: 错误 
2008-06-14 15:34
冰彩虹
Rank: 4
来 自:上海
等 级:贵宾
威 望:14
帖 子:806
专家分:44
注 册:2007-6-28
收藏
得分:0 
没听明白

Flying without wings
2008-06-14 21:17
快速回复:无语的错误!特急!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.030652 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved