Click here to Skip to main content
15,910,773 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone,

I have one windows application in which i have to select date range from my access database. What i want to do is I want to select a range in which the Birthday's of my friends lies (i.e birthday's falls in this range) so i need to select only date and month, here nothing to do with year. Below is my code

VB
cn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source =" & Application.StartupPath & "\EDS.accdb"
       cn.Open()
       'Dim mstrFormTim As String
       Dim date1, date2, month1, month2, dat1, dat2, mon1, mon2 As String
       Dim dt1, dt2 As String
       date1 = DateTimePicker1.Value.Date
       date2 = DateTimePicker2.Value.Date
      
       dat1 = DatePart("d", date1)
       If dat1.Length = 1 Then
           dat1 = "0" & dat1
       End If
       dat2 = DatePart("d", date2)
       If dat2.Length = 1 Then
           dat2 = "0" & dat2
       End If
       mon1 = DatePart("M", date1)
       If mon1.Length = 1 Then
           mon1 = "0" & mon1
       End If
       mon2 = DatePart("M", date2)
       If mon2.Length = 1 Then
           mon2 = "0" & mon2
       End If
       dt1 = dat1 & "-" & mon1
       dt2 = dat2 & "-" & mon2
      
       mStrFinalQuery = "select Name, DOB from DateofBirth where format(DOB,""dd-MM"") between '" & dt1 & "' and '" & dt2 & "'"
       cmd = New OleDbCommand(mStrFinalQuery, cn)
       cmd.ExecuteNonQuery()
       'Me.Close()
       ReportsGridview.Show()
       cn.Close()


here I am getting the wrong data, anyone can help me??
Posted
Updated 11-Jul-12 23:19pm
v2
Comments
graciax8 12-Jul-12 5:13am    
i just want to clarify the name of the table is DateofBirth?
ckulasekaran 12-Jul-12 7:42am    
Check datetimepicker's date format
ZurdoDev 12-Jul-12 8:26am    
Look at what mStrFinalQuery ends up to be. Run it in SQL management studio and figure out where the issue is.

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