tags:

views:

41

answers:

3

i have created a database in mysql5.0. i want to display the data from it. it has table named login. it has 2 columns username and password. in form i have 2 text fields username and password i just want to validate input with database values and display message box. connection from vb to database is established successfully. but its not validating input. its giving error as 'object required'. please any body help i'm new to vb.

i'm using vb6 and mysql5.0 thank you

code is:

public con As ADOB.connection
public rs2 As new ADOB.Recordest

public sub preconnection()
    set con = New connection
    set rs = New recordest
    set con = New ADOB.connection
    con.connectionString = "DRIVER = {Mysql ODBC 3.51 driver};"_
                 & "SERVER = localhost;"_
                 & "DATABASE = vbtest;"_
                 & "UID = root;"_
                 & "PWD = ;"
    con.cursorLocation = 
    con.open
end sub

sql = "select *from login"
set rs = con.execute (sql)
if rs.BOF = False Then
    While Not rs.EOF
        If Ucase(txtlogin.text = trim(rs(0)) Ad txtpassword.text = Trim(rs(1)) Then
            username = rs(0)
            loginname = True

            MsgBox("welcome")
        End if
        rs.movenext
     wend
End Sub
+2  A: 

You've declared a variable rs2 but you're not using it anywhere; instead, you're referring throughout to a non-existent variable rs

CodeByMoonlight
+1  A: 

There are a few problems with your code sample:

  • continuation convention in VB6 is like so:

        con.connectionString = "DRIVER = {Mysql ODBC 3.51 driver};" & _
           "SERVER = localhost;" & _
           "DATABASE = vbtest;" & _
           "UID = root;" & _
           "PWD = ;"
    
  • typo: sql = "select *from login" -> sql = "select * from login"

  • typo: If Ucase(txtlogin.text = trim(rs(0)) Ad txtpassword.text -> If Ucase(txtlogin.text = trim(rs(0)) And txtpassword.text

hawbsl
A: 

As a tip, if you set "Option Explicit", VB6 should point out some of the typos, etc for you. If you don't have this set, but refer to a non existent variable (like rs) it will just create it for you as you use it.

sql = "select *from login"

Should probably be:

sql = "select * from login"

You should probably declare sql.

If Ucase(txtlogin.text = trim(rs(0)) Ad txtpassword.text = Trim(rs(1)) Then

should be

If Ucase(txtlogin.text = trim(rs(0)) And txtpassword.text = Trim(rs(1)) Then

Also, I think it's more efficient to use StrComp than UCASE - although both will work.

pm_2