Click here to Skip to main content
15,881,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i am making an app for gate pass expiry
so in main form i put one data grid view the data grid view will show the data of expiring gate passes in next 1 month

i write the below code but it is showing the list of gate passes which are going to expire in next 2 months also


please help

What I have tried:

Private Sub MDIParent1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
expiryalert()
End Sub
Public Sub expiryalert()
Try
Dim da As New SqlDataAdapter
Dim ds As New DataSet
Dim cmd As SqlCommand
connection()
cmd = New SqlCommand("select * from gatepassdetails where expiry > '" & Format(Today.AddMonths(1), "MM/dd/yyyy") & "'", connsql)
da.SelectCommand = cmd
da.Fill(ds, "gatepassdetails")
data_expired.DataSource = ds
data_expired.DataMember = "gatepassdetails"
Catch ex As Exception
MsgBox(ex.Message.ToString)
connsql.Close()
End Try
End Sub
Posted
Updated 1-Dec-16 2:24am
Comments
ZurdoDev 1-Dec-16 8:10am    
Don't you want where expiry is < ?
sufyankadri 1-Dec-16 8:13am    
thanks for your help.
King Fisher 1-Dec-16 8:18am    
use between operator:
select * from gatepassdetails where expiry between 'today' and 'endDate'

As mentioned in the comments, what you really want to use is less than. If you translate it into English, what you currently have is where the expiry date is later than a month from now. What you really want is what is less than a month from now. I'm not sure if your system needs it or not but you may want to include and greater than or equal to today's date.
 
Share this answer
 
Comments
sufyankadri 1-Dec-16 8:21am    
thanks
i need i should get alert before one month of expiry
again thanks for your solution.
Rather than using AddMonths and Format (plus a string concatenation) consider using DATEADD:
VB
cmd = New SqlCommand("SELECT * FROM gatepassdetails WHERE expiry < DATEADD(mm, 1, GETDATE())", connsql)
Which keeps it all inside SQL.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900