akamini 7 Newbie Poster

Thanks to Daniweb I've almost finished my project just the last few bits to do e.g to prevent double bookings


I've had a search around and found
http://www.daniweb.com/forums/thread129022.html

which has helped me to make this

Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim con As New OleDb.OleDbConnection
        Dim OleDBCon As System.Data.OleDb.OleDbConnection
        Dim ds As New DataSet
        Dim da As System.Data.OleDb.OleDbDataAdapter
        Dim sql As String

        Dim BookingsLessonStart As Date
        Dim BookingsLessonEnd As Date
        Dim BookingsLessonDate As String

        BookingsLessonStart = dtpLessonTime.Value
        MsgBox(BookingsLessonStart)

        BookingsLessonEnd = dtpLessonEnd.Value
        MsgBox(BookingsLessonEnd)

        BookingsLessonDate = Format(dtpLessonDate.Value, "MM/dd/yyyy")
        MsgBox(BookingsLessonDate)
        con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = \DrivingSchool.mdb"
        sql = "SELECT * FROM tblBookings WHERE LessonTime >= #" & BookingsLessonStart & "#  AND LessonDate=#" & BookingsLessonDate & "#"

        'Or #" & BookingsLessonStart & "# <= LessonEnd "
        'AND LessonDate=#" & BookingsLessonDate & "# Or #" & BookingsLessonStart & "# <= LessonEnd  AND LessonDate=#" & BookingsLessonDate & "#"

        OleDBCon = New System.Data.OleDb.OleDbConnection(con.ConnectionString)


        da = New System.Data.OleDb.OleDbDataAdapter(sql, OleDBCon)
        OleDBCon.Open()
        da.Fill(ds, "BookingsWeek")
        MaxRows = ds.Tables("BookingsWeek").Rows.Count
        MsgBox(MaxRows)
    End Sub

currently I'm testing it using time on a specific date which I know is booked but the results show 0 which means it'd allow for double bookings.

I've commented out some other code which i've tried. What I'm trying to achieve is so that if the number of rows return is 1 or more then they cant book but the sql is returning 0 even though I know there is a booking on that time.