Wa Eil Wa Eil - 1 month ago 6
Vb.net Question

VB.net Msaccess Retrieving data where DATE is BEHIND/LESS THAN the DATE TODAY

I am creating a project to be defend next week about a gym management system. the problem is, i cant inform the user if there is an expired promo. i used these query but its not displaying the right data

If Not con.State = ConnectionState.Open Then
con.Open()
End If

Try
Dim da As New OleDb.OleDbDataAdapter("SELECT MemberID,Nickname,PromoStatus,PromoStart,PromoEnd FROM Members WHERE PromoEnd < now() AND PromoStatus = 'Active'", con)
Dim dt As New DataTable
da.Fill(dt)
MembersDataGridView.DataSource = dt
con.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try


I tried these codes and its not displaying the data where the PromoEnd is less than today/ the PromoEnd is behind the date today. i tried also the

SELECT MemberID,Nickname,PromoStatus,PromoStart,PromoEnd FROM Members WHERE PromoEnd < '"& dateandtime.today.date &"' AND PromoStatus = 'Active'", con


still its not retrieving the right data. thank u for your helps and any suggestions.
ps: shortdate format is what im using for the dates. (0/0/0000)

Answer

should i change it as dateandtime in the msaccess?

Yes, always store date and time as data type DateTime.

Then your SQL can be reduced to:

"SELECT MemberID, Nickname, PromoStatus, PromoStart, PromoEnd FROM Members WHERE PromoEnd < Date() AND PromoStatus = 'Active'"
Comments