【问题标题】:vb6 displaying problemvb6显示问题
【发布时间】:2010-03-19 11:50:39
【问题描述】:

我在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

【问题讨论】:

  • 哪一行出现错误?

标签: mysql vb6 adodb


【解决方案1】:

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

【讨论】:

    【解决方案2】:

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

    • VB6 中的延续约定是这样的:

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

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

    【讨论】:

      【解决方案3】:

      作为提示,如果您设置“选项显式”,VB6 应该为您指出一些错别字等。如果你没有这个集合,但引用一个不存在的变量(如 rs),它会在你使用它时为你创建它。

      sql = "select *from login"

      应该是:

      sql = "从登录中选择 *"

      你可能应该声明 sql。

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

      应该是

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2023-03-31
        • 2012-01-11
        • 1970-01-01
        • 1970-01-01
        • 2011-09-29
        • 2016-03-24
        • 1970-01-01
        相关资源
        最近更新 更多