| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 594 人关注过本帖
标题:高手帮忙看看...
只看楼主 加入收藏
linxiaokun123
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2008-3-24
收藏
 问题点数:0 回复次数:2 
高手帮忙看看...
关键字 'user' 附近有语法错误...不知道什么原因,请大家帮忙看看
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.Data.SqlClient;
using System.Web.Configuration;
using System.Security.Cryptography;//使用HashPasswordForStringInConfigFile()函数需要的命名空间


public partial class admin_admin_manager : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Literal1.Visible = false;
    }


    protected void add_Click(object sender, EventArgs e)
    {

    }

    protected void ok_Click(object sender, EventArgs e)
    {
        string name = username.Text.ToString();
        string passwd = password.Text.ToString();
        if (Session["checkcode"] == null)
        {
            Literal1.Text = "系统错误,不能生成验证码";
            Literal1.Visible = true;
            return;
        }
        if (chkcode.Text == "")
        {
            Literal1.Text = "请输入验证码";
            Literal1.Visible = true;
            return;
        }
        if ((Session["checkcode"].ToString(), chkcode.Text, true) != 0)
        {
            Literal1.Text = "验证码错误,请输入正确的验证码";
            Literal1.Visible = true;
            return;
        }
        if (name == "" | passwd == "")
        {
            Literal1.Visible = true;
            Literal1.Text = "请输入用户名和密码!";
        }
        else
        {
            string settings = Convert.ToString(ConfigurationManager.ConnectionStrings["cangku"]);;
            SqlConnection connection = new SqlConnection(settings);
            connection.Open();
            string mysql = "select * from user where userID=" + "'" + name + "'" + "and userPW=" + "'" + passwd + "'";
            SqlCommand mycmd = new SqlCommand(mysql, connection);
            SqlDataReader mydr = mycmd.ExecuteReader();
            try
            {
                if (mydr.Read())
                {
                    //Session["UserName"] = mydr[0];    //把用户名写入Session对象
                    //Session["adminGrade"] = mydr[2];   //把权限写入Session对象
                    Response.Write("<script>alert('登陆成功')</script>");
                    string sUrl = "Default.aspx?id=" + username.Text;
                    Response.Redirect(sUrl);
                }
                else
                {
                    Literal1.Visible = true;
                    Literal1.Text = "用户名或密码错误!";

                }
            }
            catch
            {

            }
            finally
            {
                mydr.Close();
                connection.Close();
            }
        }
    }
    protected void clear_Click(object sender, EventArgs e)
    {
        username.Text = "";
        password.Text = "";
        chkcode.Text = "";
    }
    protected void ButtonNew_Click(object sender, EventArgs e)
    {
    }
}
用户代码未处理SqlException
关键字 'user' 附近有语法错误。
搜索更多相关主题的帖子: 关键字 空间 命名 
2008-03-24 09:16
YSKING
Rank: 5Rank: 5
来 自:中国绿城
等 级:贵宾
威 望:16
帖 子:1380
专家分:25
注 册:2006-11-11
收藏
得分:0 
把user改为[user]

仍然自由自我,永远高唱我歌,走遍千里...
2008-03-24 11:52
寂寞的刺猬
Rank: 1
等 级:新手上路
帖 子:111
专家分:0
注 册:2008-3-23
收藏
得分:0 
楼上正解,对于某些特殊的表,必须用中括号扩起来,建议你以后不管是什么表,都用中括号扩起来,这样不容易出错。

我的博客  http://wlb.wlb.blog.
2008-03-24 22:28
快速回复:高手帮忙看看...
数据加载中...
 
   



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

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