Reputation: 55
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.
Upvotes: 0
Views: 83
Reputation: 706
There is no Problem in your query, you just need to Fill the adapter to let it know what to populate.
Upvotes: 1
Reputation: 235
You forgot
adapter3.Fill(dtoffenseinfo3)
That's what's missing. :)
Upvotes: 2
Reputation: 54417
Who says that your query can't return any rows? You're not actually executing it so how would you even know? What's the point of the data adapter if you don't call its Fill
method?
Upvotes: 2