MySQLCommand Returns no values

I have the following code in a form that tries to take data from two tables connected by a LEFT JOIN and write the results to a text file. If I run the query in MySQL Query Browser it works as expected. For test purposed only I ran the query selectying data from 1 table only (LEFT JOIN redundant I know but trying to see if there was a syntax issue) and it worked as expected. Am I missing something in trying to run this query from inside a VBasic Express form.

       Try
            Dim myQuery As String
            myQuery = "SELECT utName, utRating, ulTotSeconds FROM usrtime u "
            myQuery = myQuery & "LEFT JOIN usrList l "
            myQuery = myQuery & "ON u.utName = l.nameWeb "
            myQuery = myQuery & "WHERE ASCII(u.utName) > 64 "
            myQuery = myQuery & "ORDER BY u.utName"

            Dim myConn As New MySqlConnection(connStr)
            Dim myCmd As New MySqlCommand(myQuery, myConn)

            myConn.Open()

            Dim myReader As MySqlDataReader
            myReader = myCmd.ExecuteReader()

            While myReader.Read()
                objWrite.WriteLine((myReader.GetString(0) & ", " & _
                    myReader.GetString(1) & ", " & myReader.GetString(2)))
            End While

            myReader.Close()
            myConn.Close()
            objWrite.Close()

Open in new window

clironAsked:
Who is Participating?
 
Tomas Helgi JohannssonCommented:
And are the columns utName, utRating, ulTotSeconds all String columns ?

http://dev.mysql.com/doc/refman/5.0/es/connector-net-examples-mysqldatareader.html

Regards,
    Tomas Helgi
0
 
Michael701Commented:
Why are you doing the LEFT JOIN if you're only using columns from usrtime?

myQuery = "SELECT utName, utRating, ulTotSeconds FROM usrtime "
            myQuery = myQuery & "WHERE ASCII(utName) > 64 "
            myQuery = myQuery & "ORDER BY utName"
0
 
Michael701Commented:
next check for errors after the ExecuteReader()

should: ulTotSeconds be utTotSeconds to keep with the naming conventions? Could this be causing the empty data set?
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
clironAuthor Commented:
As I said I only took values from 1 table to make sure there was nothing wrong with the syntax. The problem arises when I try and take values from 2 tables.
0
 
clironAuthor Commented:
ulTotSeconds is a value from the 2nd table (ut = usrTime, ul = usrList)
0
 
Tomas Helgi JohannssonCommented:
           Hi!

Try this
ON TRIM(u.utName) = TRIM(l.nameWeb)

If this is the case you have in either column of these tables values with blanks that can interfere with the result you want.
And you would need to correct those values.

Also check if these joins would help in the same way
UPPER(u.utName) = UPPER(l.nameWeb)
or
TRIM(UPPER(u.utName)) = TRIM(UPPER(l.nameWeb))

Hope this helps.

Regards,
     Tomas Helgi
0
 
clironAuthor Commented:
Tried that but still no joy. I have employed the same query but outputted to a datagrid view and it works as expected. There must be something quirky with the executereader.

Thanks.
0
 
Tomas Helgi JohannssonCommented:
And also make sure that you catch the MySQLException

http://dev.mysql.com/doc/refman/5.0/es/connector-net-examples-mysqlexception.html

Regards,
   Tomas Helgi
0
 
clironAuthor Commented:
MySQLException threw up a data is null error message. Have got around the issue with including an IFNULL(fld1,fld2) expression and the Execute reader is now working as expected.

Thanks.

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.