protected void Button1_Click(object sender, EventArgs e)
    {
        if (TextBox1.Text.Trim() == "" || TextBox2.Text.Trim() == "")
        {
            Label3.Text = "你还没有输入用户名和密码哩!";                                   // 检查这二个输入框是否未输入东西便按了提交
        }        else
        {
            SqlConnection conn = new SqlConnection("Data Source=JACKSON;Initial Catalog=xin;User ID=sa;Password=123456");
            conn.Open();
            SqlCommand cmd = new SqlCommand("select * from tuser where name='"+TextBox1.Text.Trim()+"',and password='"+TextBox2.Text.Trim()+"'",conn);
            SqlDataAdapter adp = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            adp.Fill(ds,"tuser");
            conn.Close();
            if (ds.Tables[0].Rows.Count > 0)
            {
                Label3.Text = "登录成功!";
                Response.Write("登录成功,欢迎回来");
高手大哥,我写一个简单的登录验证代码,运行时“adp.Fill(ds,"tuser");” 这里总是提示:',' 附近有语法错误。我看了好半天就是一直看不出来错在哪里,谢谢麻烦牛人大哥帮看一下,到底怎么回事哈! 在线等,谢谢~

解决方案 »

  1.   

    adp.Fill(ds,"tuser");这句语法没有错误啊~
      

  2.   

    是你的sql语句错误,把你生成的sql语句贴出来看看就知道了,或者你自己放到数据库看看
      

  3.   

    写错了,这么粗心
    SqlCommand cmd = new SqlCommand("select * from tuser where name='"+TextBox1.Text.Trim()+"' and password='"+TextBox2.Text.Trim()+"'",conn);
      

  4.   

    看见红色的那个逗号了没有??多余的,去掉就OK了
    SqlCommand cmd = new SqlCommand("select * from tuser where name='"+TextBox1.Text.Trim()+"',and password='"+TextBox2.Text.Trim()+"'",conn);
      

  5.   

    name='"+TextBox1.Text.Trim()+"',and password
    把中间的逗号去掉,在加上空格
      

  6.   

    name='"+TextBox1.Text.Trim()+"',and
    不解释了
      

  7.   

    sql语句问题,and前多了个逗号!