[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

MySQLCommand Returns no values

Posted on 2011-04-26
10
Medium Priority
?
316 Views
Last Modified: 2012-05-11
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

0
Comment
Question by:cliron
  • 4
  • 3
  • 2
9 Comments
 
LVL 19

Expert Comment

by:Michael701
ID: 35473243
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
 
LVL 19

Expert Comment

by:Michael701
ID: 35473253
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
 

Author Comment

by:cliron
ID: 35473255
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:cliron
ID: 35473260
ulTotSeconds is a value from the 2nd table (ut = usrTime, ul = usrList)
0
 
LVL 26

Expert Comment

by:Tomas Helgi Johannsson
ID: 35473745
           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
 

Author Comment

by:cliron
ID: 35473786
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
 
LVL 26

Accepted Solution

by:
Tomas Helgi Johannsson earned 2000 total points
ID: 35473843
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
 
LVL 26

Assisted Solution

by:Tomas Helgi Johannsson
Tomas Helgi Johannsson earned 2000 total points
ID: 35473865
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
 

Author Comment

by:cliron
ID: 35474008
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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
In this article, we’ll look at how to deploy ProxySQL.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month18 days, 6 hours left to enroll

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question