vb6显示问题

发布于 2024-08-25 17:47:08 字数 1007 浏览 6 评论 0原文

我在mysql5.0中创建了一个数据库。我想显示其中的数据。它有名为登录的表。它有 2 列用户名和密码。在表单中,我有 2 个文本字段用户名和密码,我只想使用数据库值验证输入并显示消息框。从 vb 到数据库的连接已成功建立。但它不验证输入。其给出的错误为“需要对象”。请任何人帮助我,我是VB新手。

我正在使用 vb6 和 mysql5.0 谢谢

代码是:

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

娜些时光,永不杰束 2024-09-01 17:47:08

您已经声明了一个变量rs2,但您没有在任何地方使用它;相反,您自始至终都引用了一个不存在的变量 rs

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

◇流星雨 2024-09-01 17:47:08

您的代码示例存在一些问题:

  • VB6 中的延续约定如下所示:

     con.connectionString = "DRIVER = {Mysql ODBC 3.51 驱动程序};" & _
           “服务器=本地主机;” & _
           “数据库= vbtest;” & _
           “UID=根;” & _
           “口令=;”
    
  • typo: sql = "select *from login" -> sql =“从登录中选择*”

  • 拼写错误:If Ucase(txtlogin.text = trim(rs(0)) Ad txtpassword.text -> If Ucase(txtlogin.text = trim(rs(0)) 和 txtpassword.text

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

一江春梦 2024-09-01 17:47:08

作为提示,如果您设置“Option Explicit”,VB6 应该为您指出一些拼写错误等。如果您没有此设置,但引用了一个不存在的变量(如 rs),它只会在您使用它时为您创建它。

sql = "select *from login"

可能应该是:

sql = "select * from login"

您可能应该声明 sql.

如果 Ucase(txtlogin.text = trim(rs(0)) Ad txtpassword.text = Trim(rs(1)) 那么

应该是

If Ucase(txtlogin.text = trim(rs(0)) 并且 txtpassword.text = Trim( rs(1)) 然后

另外,我认为使用 StrComp 比 UCASE 更有效 - 尽管两者都可以工作。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文