Results 1 to 2 of 2

Thread: VB6 / MySQL Help

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2006
    Posts
    114

    VB6 / MySQL Help

    Hello there
    I use an ADODB connection Through MySQL 5.0; the provider is ODBC. My problem is setting a SQL querie to a variable (vb6). For example, here is my vb/SQL querie.
    VB Code:
    1. rs.Open "SELECT username, password FROM tehtable WHERE username='" & Text1.Text & "' AND password ='" & Text2.Text & "'", conn
    i want to do
    VB Code:
    1. return = rs.Open("SELECT username, password FROM tehtable WHERE username='" & Text1.Text & "' AND password ='" & Text2.Text & "'", conn)
    but that returns errors as it says it expects a function on ".Open"
    if any of you could help that would be great

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: VB6 / MySQL Help

    The open method does a lot more than return a value - it populates an entire recordset (which can contain multiple rows/columns of data, and all associated meta-data). Even in your example, there are two fields being returned by the SQL, so which value would it give (if it was vaid)?

    After running the (first) rs.Open line you need to work with the rs object, like this:
    VB Code:
    1. If rs.EOF Then
    2.   Msgbox "No data found"
    3. Else
    4.   MsgBox "Username: " & rs("username").Value
    5.   myVar = rs("password").Value
    6. End If

    Note that it is possible to get multiple rows of data returned, so you need to be able to loop thru them, which you can do like this:
    VB Code:
    1. Else
    2.   Do While Not rs.EOF
    3.     MsgBox "Username: " & rs("username").Value
    4.     myVar = rs("password").Value
    5.     rs.MoveNext
    6.   Loop
    7. End If

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width