0

这是我的登录代码。我正在研究我的 dbms 项目。我已删除所有错误,因为错误列表显示 0 个错误,但是当我执行此操作时,我的网页顶部出现此错误,即关键字“用户”附近的语法不正确。在剩下的页面上,出现了我的登录表单。我不知道如何解决这一切。请尽快告诉我。这是登录表单页面的代码。protected void Button1_Click(object sender, EventArgs e) { try { //为链接数据库建立必要的连接

        SqlConnection conn = new SqlConnection("Data Source=BUSHRA-PC\\SQLEXPRESS;Initial Catalog=fb;Integrated Security=True");

        conn.Open(); // openning connection
        SqlCommand cmd = new SqlCommand("select * from user where Userid='" + TextBox1.Text + "'", conn);
        //cmd.Connection = conn;
        SqlDataReader dr = null;
        dr = cmd.ExecuteReader();
        if (dr.Read())
        {
            TextBox1.Text = dr["Userid"].ToString();
        }
        cmd.Connection = conn;
        while (dr.Read())
        {
            Application["Userid"] = dr[0].ToString();
            Application["Password"] = dr[1].ToString();
            Application["Rollid"] = dr[2].ToString();

            if (dr[0].ToString() == TextBox1.Text && dr[1].ToString() == TextBox3.Text)
                {
                    if (Convert.ToInt16(dr[2].ToString()) == 2)
                    {
                        Response.Redirect("Admin.aspx");
                    }


                else if (Convert.ToInt16((dr[2])) == 1)

                    {
                        Response.Redirect("StudentFB.aspx");
                    }

                }   
        }
    }
    catch (Exception ex)
    {
        Response.Write(ex.Message); // if try fails display the error

    }
4

1 回答 1

2

user是保留关键字。引用它,用双引号"user"或括号[user]

于 2012-11-23T14:26:46.423 回答