写了个登陆代码老是提示登陆失败,
我实在找不到原因了,不知道是不是哪个SQL语句有没有把两个文本框的值提出来,如果不是应该怎么办??如果不是,那是哪个地方出了问题????好急,高手,帮帮小弟.
两段代码都同样在下面了:都提示登陆失败
  1:第一个登陆代码
       Dim con As New SqlConnection
        con.ConnectionString = "server=BT-BBT;uid=adoxq;pwd=86221xq;database=tz"
        con.Open()        Dim str As String = "select * from rigester where user='" + TextBox1.Text + "' and pwd='" + TextBox2.Text + "'"
        Dim cmd As New SqlCommand(str, con)
        Dim dr As SqlDataReader = cmd.ExecuteReader
        If dr.Read() Then
            Response.Redirect("adocoffee\wangye\czdl.html")
        Else
            Response.Write("<script languge='javascript'> alert('登录失败,');window.top.location.href='login.aspx';</script>;return")
   
    2:第二个登陆代码
 Dim con As New SqlConnection
        con.ConnectionString = "server=BT-BBT;uid=adoxq;pwd=86221xq;database=tz"        Dim ds As DataSet = New DataSet
        Dim da As SqlDataAdapter = New SqlDataAdapter("select * from rigester where user='" + TextBox1.Text + "' and pwd='" + TextBox2.Text + "'", con)
        con.Open()
        da.Fill(ds)
        If ds.Tables(0).Rows.Count = 0 Then
            Response.Write("<script languge='javascript'> alert('登录失败,');window.top.location.href='login.aspx';</script>;return")        Else
            Session("user") = TextBox1.Text
            Response.Redirect("adocoffee/wangye/czdl.html")        End If
        con.Close()
        ds.Clear()    

解决方案 »

  1.   

    Dim str As String = "select * from rigester where user= '" + TextBox1.Text + " ' and pwd= '" + TextBox2.Text + " '" 
    字符串拼的看不懂啊,是不是应该这样拼啊:
    “select * from rigester where user=” + TextBox1.Text + “and pwd=” + TextBox2.Text; 
    个人愚见!   
      

  2.   

    sql语句应该是楼主这样写的,char,varchar类型的都要带单印号。
    搂主的代码貌似没有什么问题。
      

  3.   

    "select * from rigester where user= '" + TextBox1.Text + " ' and pwd= '" + TextBox2.Text + " '" 
     ~~~多了空格                       ~~~多了空格改成
    "select * from rigester where user= '" + TextBox1.Text + "' and pwd= '" + TextBox2.Text + "'" 
      

  4.   

    Dim str As String = "select * from rigester where user= '" + TextBox1.Text + " ' and pwd= '" + TextBox2.Text + " '"
    ------------------------------------
    首先注意红色部分之间应该加个空格!!!!
    Dim str As String = "select * from rigester where user= '" + TextBox1.Text + " '  and pwd= '" + TextBox2.Text + " '"另外跟踪一下,看是哪的问题。。
      

  5.   

    貌似其他地方不该有空格的,楼主也多了空格。。这里的格式看不太清楚,楼主自己检查一下吧
    整体应该如下:
    Dim str As String = "select * from rigester where user=  '" + TextBox1.Text + "'  and pwd=  '" + TextBox2.Text + "'" 
      

  6.   

    单步调试下,看str的值到底是什么
      

  7.   

           
    + 应该换成 & 
    象姓名这样:
    Dim str As String = "select * from rigester where user= '" & TextBox1.Text & " ' and pwd= '" & TextBox2.Text & " '" 
           
      

  8.   

    Dim str As String = "select * from rigester where user= '" + TextBox1.Text + " ' and pwd= '" + TextBox2.Text + " '" 
    ------------------------------------------------------Dim str As String = "select * from rigester where username= '" + TextBox1.Text + " ' and pwd= '" + TextBox2.Text + " '" 你把你数据库表里的user 字段该成username 这样就可以了,user数据库系统自带的敏感字段.......
      

  9.   

    好开心啊,真是好激动啊,我几个星期不吃不喝不睡都没有调试出来,现在终于出来了实在谢谢onlyadou,太谢谢你了啊,没有你的指点,打死我都不想不到数据库还有这么一招,真的我打死都想不到,数据库里还有user这个敏感的字段。同时还要感谢那么多关心,和帮助我的,他们说的空格,或者把+换成&(其实都是一样) ,还有单引号双引号。这些我知道,但还是要谢谢你们对我的帮助,以后还请多多指教。在这里还要说几句感谢,onlyadou。同时也要提醒朋友们,数据库里还真有这么一回事,关于user是敏感字段,但同时我还注意到,date也是个敏感的字段。好了,感谢大家了,以后还请各位多多指教。
      

  10.   

    问题解决了,恭喜楼主!
    提个小建议啊:你的代码存在安全漏洞啊,很容易实现SQL注入攻击
    是不能使用的!
    Dim str As String = "select * from rigester where user= '" & TextBox1.Text.Trim("'","''") & " ' and pwd= '" & TextBox2.Text.Trim("'","''")  & " '" 
      

  11.   

    楼主的sql语句有问题,漏洞,sql注入
      

  12.   

    "select * from rigester where [user]= '" + TextBox1.Text + " ' and pwd= '" + TextBox2.Text + " '"
    楼主请输入用户名为 ' OR 1=1  密码随便...看看能不能登陆哦?