Flash Games

 FAQ   Search   Members   Groups   Register  User Control Panel      Login 

Your time now:
Mon Nov 23, 2009 9:02 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 1 post ]  Bookmark and Share
Author Message
 Post subject: Problem with WHERE in SQL only in code
PostPosted: Wed Apr 08, 2009 7:09 pm 
Offline

Joined: Wed Apr 08, 2009 7:06 pm
Posts: 1
Hi Everyone, Thanks ahead of time for the help.

My Code:
Code:
    Private Sub btnExport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExport.Click
        Dim Conn As New ADODB.Connection
        Dim Rec As New ADODB.Recordset
        Dim SQLqry As String

        On Error GoTo btnExport_Error

        'Build SQL Query
        SQLqry = "SELECT     ClockData.[Date], Employee.FirstName, Employee.LastName, ClockData.TimeIn, ClockData.TimeOut, ClockData.Comment" & _
                 " FROM (Employee INNER JOIN ClockData ON ClockData.EmployeeNumber = Employee.EmployeeNumber)" & _
                 " WHERE (ClockData.[Date] <= #4/2/2009#) AND (ClockData.[Date] >= #4/1/2009#) AND (Employee.FirstName = 'Shai')"

        Debug.Print(SQLqry)
        'Open connection to database delared on Form1_Activated
        Conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & dbPath & " ;Persist Security Info=True;User ID=admin;Jet OLEDB:Database Password=twinvolcano"
        Conn.Open()
        Rec.Open(SQLqry, Conn, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockPessimistic)
        'Go through records
        While Not Rec.EOF
            'Do Something with records
            Debug.Print(Rec.Fields("FirstName").Value)
            'Goto next record in recordset
            Rec.MoveNext()
        End While

        'Close database connections
        Rec.Close()
        Conn.Close()

        Exit Sub
btnExport_Error:
        ' Describe the error to the user.
        MsgBox("Unexpected error" & _
            Str$(Err.Number) & _
            " in subroutine DoSomething." & _
            vbCrLf & _
            Err.Description)
        Exit Sub


    End Sub


I can take the debug.print(SQLqry) output
Code:
SELECT     ClockData.[Date], Employee.FirstName, Employee.LastName, ClockData.TimeIn, ClockData.TimeOut, ClockData.Comment FROM (Employee INNER JOIN ClockData ON ClockData.EmployeeNumber = Employee.EmployeeNumber) WHERE (Employee.FirstName = 'Shai')

from the immediate window, put it in the VB query designer and it returns results:
Snippete of results:
Code:
10/14/2008 12:00:00 AM   Shai   Perednik   10/14/2008 7:23:00 AM   10/14/2008 9:21:00 AM   NULL
10/14/2008 12:00:00 AM   Shai   Perednik   10/14/2008 9:21:00 AM   10/14/2008 10:40:00 AM   NULL
10/14/2008 12:00:00 AM   Shai   Perednik   10/14/2008 10:40:00 AM   10/14/2008 12:48:00 PM   NULL
10/14/2008 12:00:00 AM   Shai   Perednik   10/14/2008 1:40:00 PM   10/14/2008 3:18:02 PM   NULL
10/14/2008 12:00:00 AM   Shai   Perednik   10/14/2008 3:24:51 PM   10/14/2008 5:29:00 PM   NULL
10/15/2008 12:00:00 AM   Shai   Perednik   10/15/2008 7:28:00 AM   10/15/2008 12:20:00 PM   NULL
10/15/2008 12:00:00 AM   Shai   Perednik   10/15/2008 1:05:00 PM   10/15/2008 6:18:00 PM   NULL
10/16/2008 12:00:00 AM   Shai   Perednik   10/16/2008 7:57:00 AM   10/16/2008 12:34:00 PM   NULL
10/16/2008 12:00:00 AM   Shai   Perednik   10/16/2008 1:26:00 PM   10/16/2008 5:12:00 PM   NULL
10/17/2008 12:00:00 AM   Shai   Perednik   10/17/2008 7:53:00 AM   10/17/2008 10:01:04 AM   NULL
10/17/2008 12:00:00 AM   Shai   Perednik   10/17/2008 10:09:11 AM   10/17/2008 12:24:00 PM   NULL
10/17/2008 12:00:00 AM   Shai   Perednik   10/17/2008 2:54:00 PM   10/17/2008 5:03:00 PM   NULL
10/20/2008 12:00:00 AM   Shai   Perednik   10/20/2008 7:41:00 AM   10/20/2008 12:29:00 PM   NULL
10/20/2008 12:00:00 AM   Shai   Perednik   10/20/2008 1:10:00 PM   10/20/2008 5:22:00 PM   NULL
10/21/2008 12:00:00 AM   Shai   Perednik   10/21/2008 7:46:00 AM   10/21/2008 12:46:42 PM   NULL


BUT, in code, watching the locals window for rec.EOF and rec.BOF both return true and therefore no results.

So whats wrong? Why does this work in VB Query Designer but not in code?

If I remove the WHERE statement than the results return fine as expected. But its returning ALL of the results which is no good.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group - Flash Games - TNX Invitation Code - TNX Review


Webmaster - Excruciating - Johnathan - Kotik - Ash - Tomi - rangana - Phate - dflynn - Medley