Search code examples
sqlvb.netms-access-2010oledb

What's missing / wrong with my SQL Query? (Doesn't return any row)


Why doesn't my query able to return any rows and not go to Else in my conditional statement?

 For i As Integer = 0 To dtoffenseinfo2.Rows.Count - 1
            Dim dtoffenseinfo3 As New DataTable              
            Dim adapter3 As New OleDbDataAdapter("SELECT SUM(Price) AS TPRICE FROM tblFuelTransactionLogs " & _
                              "WHERE Created_Date=#" & Format(dtoffenseinfo2.Rows(i).Item("Dates"), "Short Date") & "#", DBConnection)

            If dtoffenseinfo3.Rows.Count <= 0 Then

            Else
                Dim x As Decimal = dtoffenseinfo3.Rows(0).Item("TPRICE")
                cmd.ExecuteNonQuery()
            End If
 Next

In my query, the value of dtoffenseinfo2.Rows(i).Item("Dates") comes from a lookup table with dates (for the whole month of September), and per loop, the value of the dtoffenseinfo2.Rows.(i)Item("Dates") is 09/01/2014 up to 09/30/2014 respectively.

I already have 09/18/2014 in both tables but it still doesn't return any row. I am also not getting errors. Am I using SELECT SUM() wrong? Sorry for any obvious mistake.


Solution

  • You forgot

     adapter3.Fill(dtoffenseinfo3)
    

    That's what's missing. :)