Click here to Skip to main content
15,881,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All

How can I get 1 MONTH Before Expiry Date product Details in Datagridview.

Here I use code.

VB
Dim strSQL As String = "SELECT * FROM ProductMasterA WHERE BatchExpiry <= DateAdd(+1,'M',BatchExpiry)"
Dim DaAp1 As New SqlDataAdapter(strSQL2, con)
 Dim Dset1 As New DataTable
 DaAp1.Fill(Dset1)
 DGV1.DataSource = Dset


Please tell me..
Posted

1 solution

Change your query to this:
Dim strSQL As String = "SELECT * FROM ProductMasterA WHERE BatchExpiry = (DateAdd(month,-1,getdate())"

However, the "BatchExpiry" will need to be an actual date of when you are wanting to know what the month before is. I used the getdate() function and that will check a month before that query is run. The way you are using it now will not work as it is only a string and not a variable.

Where is that value supposed to come from?
 
Share this answer
 
Comments
Maciej Los 4-Dec-13 18:00pm    
Looks perfect ;)
+5!
Richard C Bishop 4-Dec-13 18:02pm    
Thank you Maciej Los!
Navas Khanj 5-Dec-13 13:31pm    
Thanks
Richard C Bishop 5-Dec-13 15:01pm    
You are welcome.

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