Date Range using monthcalendar!!

girl

Active member
Joined
Jun 11, 2007
Messages
25
Programming Experience
Beginner
hi all

i have a problem.

i would like to retrieve data from MSSQL 2000 database. when i use 1 month calendar, my codes work fine..

sqladapter.SelectCommand = New OdbcCommand("SELECT * from " & table & " where datepart(MM,DATE) = " & Label6.Text & " AND datepart(d,DATE) = " & Label5.Text & " AND datepart(yyyy,date)=" & Label7.Text & " ", conn)

where label6,7,8.text are my dates extracted from the month calendar..

i would like to haf a date range with 2 month calendar..

how should i go about it?? i use the same way to do but there is no data retrieve out..


sqladapter.SelectCommand = New OdbcCommand("SELECT * from " & table & " where DATE between '"datepart(MM,DATE) = " & Label6.Text & " AND datepart(d,DATE) = " & Label5.Text & " AND datepart(yyyy,date)=" & Label7.Text & "' AND "datepart(MM,DATE) = " & Label8.Text & " AND datepart(d,DATE) = " & Label9Text & " AND datepart(yyyy,date)=" & Label10.Text & "' ", conn)



thnx!!
 
tried using between command in sql? If i understand you right, you want to take out all the info or records from between 2 dates, that you pick with 2x calendars..
 
yaya you had got me right, my intention is to retrieve the records from the range of date. i have 2 monthcalendar in my form.

Oh what do you mean by command in SQL?

YOu mean this SQL?

("SELECT * from " & table & " where datepart(MM,DATE) = " & Label6.Text & " AND datepart(d,DATE) = " & Label5.Text & " AND datepart(yyyy,date)=" & Label7.Text & " ", conn)
 
sqladapter.SelectCommand = New OdbcCommand("SELECT * from " & table & " where DATE between '"datepart(MM,DATE) = " & Label6.Text & " AND datepart(d,DATE) = " & Label5.Text & " AND datepart(yyyy,date)=" & Label7.Text & "' AND "datepart(MM,DATE) = " & Label8.Text & " AND datepart(d,DATE) = " & Label9Text & " AND datepart(yyyy,date)=" & Label10.Text & "' ", conn)

was thinking more about this one. wont there be possible to use Between somewhere inside the sql sentance? to get it to take out everything between the first part, and the second..
 
oh i tried using

sqladapter.SelectCommand = New OdbcCommand("SELECT * from " & table & " where DATE between '05/01/2007' AND '05/01/2007'", conn)

and it works

therefore i think there is nothing wrong with the SQL statement. i guess maybe is the way i extract the date from the calendar.. but when i try


without date range,

sqladapter.SelectCommand = New OdbcCommand("SELECT * from " & table & " where '"datepart(MM,DATE) = " & Label6.Text & " AND datepart(d,DATE) = " & Label5.Text & " AND datepart(yyyy,date)=" & Label7.Text &", conn)


it works...

so i got quite puzzled and wonder if there are any alternative method.
 
Back
Top