protected void Button1_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            {
                string username = this.TextBox1.Text;
                string password = this.TextBox2.Text;
                string str="select * from user where username ='" + username + "'";
                SqlConnection conn = new SqlConnection("Data Source=localhost;initial Catalog=sjlerp;uid=sa;pwd=****");
                SqlCommand com = new SqlCommand(str,conn);
                conn.Open();
                SqlDataReader rea = com.ExecuteReader();
                            }
        }
    }运行的红色的位置的时候总提示'user'附近有语法错误

解决方案 »

  1.   

    '" + username + "'"; 
    这里引号很奇怪
      

  2.   

    string str="select * from user where username ='" + username + "'"; 
    user是保留字
      

  3.   

    user与数据库中的系统表重名 
    在外面加个分号[user]就行了
      

  4.   

    string str="select * from [user] where username ='" + username + "'"; 
      

  5.   

    user 是关键字阿
    ....select * from [user] where....
      

  6.   

    string str="select * from [user] where username ='" + username + "'"; 正解
    我前几天才遇到的问题,也是这么解决的
      

  7.   

    string str="select * from [user] where username ='" + username + "'"; 
      

  8.   

    string str="select * from user where username ='" + username + "'";  
    user 是保留字,可以写成[user]或改名字users