我要验证用户然后登陆,循环读出数据库中用户名和密码,下面是我的代码
dim constr as string = "192.168.0.1;database=netconfer;password=zsjyc;user id=maverick;"
dim sqlstr as string = "select * from stuinfos"
dim objcon as new sqlconnection(constr)
dim objdataset as new dataset
dim objAdapter as new sqldataAdapter(sqlstr,objconn)objAdapter.fill(objconn,"stuinfos")dim username,password as stringusername = textbox1.text
password = textbox2.text
下面的代码怎样写呢?谢谢各位。

解决方案 »

  1.   

    select * from stuinfos where name=username and password2=password
      

  2.   

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim var_user, var_pass, selectcommand As String
            Dim var_count As Integer
            Dim SelectCmd_checkuser As SqlCommand
            Dim dtrResults As SqlDataReader        var_user = textuser.Text
            var_pass = TextBox2.Text
            selectcommand = "select count(*) from clerk where sn=@sn and password=@password"        If var_user <> "" Then
                If var_pass <> "" Then
                    If IsPostBack Then
                        myconnect.Open()
                        SelectCmd_checkuser = New SqlCommand(selectcommand, myconnect)
                        SelectCmd_checkuser.Parameters.Add(New SqlParameter("@sn", var_user))
                        SelectCmd_checkuser.Parameters.Add(New SqlParameter("@password", var_pass))
                        Label1.Text = SelectCmd_checkuser.ExecuteScalar
                        'var_count = dtrResults(0)
                        If CInt(SelectCmd_checkuser.ExecuteScalar) > 0 Then
                            Session("passed") = True
                            Session("person_id") = var_user
                            myconnect.Close()
                            Response.Write("<script>parent.location.href='information/main.aspx','newinformation','toolbar=no,resizable=yes,directories=no,menubar=no,location=no';</script>")
                            'Response.Redirect("information/main.aspx")
                        Else
                            myconnect.Close()
                            Label1.Text = "username or password is not correct!"
                        End If
                        myconnect.Close()
                    End If
                Else
                    Label1.Text = "Please input password!"
                End If
            Else
                Label1.Text = "Please input username!"
            End If
        End Sub
      

  3.   

    OleDbConnection myconnection=new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+ Server.MapPath("../luntang.mdb"));
    OleDbCommand mycommand=new OleDbCommand("select * from bbsuser where username='"+FormatString(username.Text)+"' and userpassword='"+FormatString(password.Text)+"'",myconnection);
    mycommand.Connection.Open();
    OleDbDataReader dr=mycommand.ExecuteReader();
    if(dr.HasRows)
    {
    dr.Read();
    Session["username"]=dr["username"];
    Session["password"]=dr["userpassword"];
    dr.Close();
    mycommand.Connection.Close();
    Response.Redirect("bbs1.aspx?leibie="+Session["leibie"]+"");
    }
    else
    {
    //错误用户名或密码
    dr.Close();
    mycommand.Connection.Close();
    }
      

  4.   

    (验证用户然后登陆)应该这样好点:string sSql="Select * from stuinfos where username='"+textbox1.text+"' and password='"+"'";
    SqlCommand cmd=new SqlCommand(sSql,objcon);int iRet=cmd.ExecuteNonQuery();if(iRet!=0)
       //这里说明已经验证成功了。
    else
       //这里说明已经验证不成功。   
      

  5.   

    循环?读出? 为什么啊?
    难道你要手动检测所有帐号和ID?
    呵呵 这样多慢  还危险啊
    就用
    select * from stuinfos where name=username and password2=password就可以拉    能读出数据就OK  读不出来就是非法
      

  6.   

    select * from stuinfos where name=username and password2=password
    OleDbCommand mycmd =new OleDbCommand(Sql,mycnn);
    OleDbDataReader myDr =mycmd.ExecuteReader();
    if(myDr.Read())
    {
    }
    else
    {
    }
      

  7.   

    dim dr as datarow
    dr = objdataset.stuinfos.Select("username='" & TextBox1.Text.Trim & "' and password='" & Textbox2.Text.Trim & '")
    If dr.Length = 0 Then
                Me.Label1.Text = "输入不正确,请重输"        Else
                Me.Label1.Text = "输入正确"
                Your Code
    End If
      

  8.   

    这是我写的代码,但没找出错误在那里
    If TextBox1.Text = "" Then
                Response.Write("<script>window.alert('用户名不能为空!')</script>")
            ElseIf TextBox2.Text = "" Then
                Response.Write("<script>window.alert('密码不能为空!')</script>")
            Else
                Try                Dim ssconstr As String = "server=192.168.0.1;database=netconfer;user id=maverickps;password=zsjyc;"
                    Dim sssqlstr As String = "select * from StuInfos where student_no='" + TextBox1.Text + "' and student_csrq='" + TextBox2.Text + "'"
                    Dim ssobjconn As New SqlConnection(ssconstr)
                    Dim ss As New SqlCommand(sssqlstr, ssobjconn)
                    Dim iRet As Int64
                    iRet = ss.ExecuteNonQuery()
                                  If iRet = 0 Then
                        Response.Write("<script>window.alert('你的用户名或者密码有误,请重新核实后再登陆!^_^')</script>")
                    Else
                        Response.Redirect("../careersystem/protocol/stu-login.aspx")
                    End If
                Catch ex As Exception
                    Response.Write("<script>window.alert('登陆失败!')</script>")
                End Try        End If
      

  9.   

    谢谢各位,登陆成功
    在成功转入下一页面stu-login.aspx后,我怎样去取得student_no 这个值
    就是在验证登录时数据库里的字段student_no与textbox1.text相对应的。
    在sut-login.aspx页面取得student_no值t
      

  10.   

    Response.Redirect("../careersystem/protocol/stu-login.aspx?student_no="& textbox1.text)dim a as string
    a=Request.QueryString("student_no")
      

  11.   

    你设定一个session值,到每个页面都可以用了,如果这个session值为空,证明没有登录,跳出login.aspx页重新登录