如何修复此语法错误?

时间:2012-11-23 14:20:25

标签: syntax-error

这是我的登录代码。我正在研究我的dbms项目。我已经删除了所有错误,因为错误列表显示0错误,但是当我执行此操作时,我的网页顶部出现此错误关键字'user'附近的语法不正确。以及剩下的页面出现了我的登录表单。我不知道怎么解决这个问题。请尽快通知我。 这是登录表单页面的代码。  protected void Button1_Click(object sender,EventArgs e)         {         尝试         {             //为链接数据库建立必要的连接

        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

    }

1 个答案:

答案 0 :(得分:2)

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

相关问题