Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
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
 
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 12-Jul-12 0:06am
Edited 12-Jul-12 0:19am
v2
Comments
iamsupergrasya at 12-Jul-12 5:13am
   
i just want to clarify the name of the table is DateofBirth?
ckulasekaran at 12-Jul-12 7:42am
   
Check datetimepicker's date format
ryanb31 at 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)

  Print Answers RSS
0 Maciej Los 474
1 ridoy 420
2 DamithSL 180
3 OriginalGriff 179
4 Richard MacCutchan 160
0 OriginalGriff 8,033
1 DamithSL 6,179
2 Sergey Alexandrovich Kryukov 5,538
3 Maciej Los 5,508
4 Kornfeld Eliyahu Peter 4,539


Advertise | Privacy | Mobile
Web04 | 2.8.141223.1 | Last Updated 12 Jul 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100