Calendar - multiple days from a db

college_amy

Regular
Joined
Jan 3, 2004
Messages
83
I am using the calendar control and allowing users to select either a single day, week or month.
I can get the actual dates selected to be highlighted on the calendar. But when selecting a week or month I can get the dates to highlight and the dates selected to display in an array.. but I can't get the data for the info in the database to pull. It will only display the data for the first date in the array. I know this is something probably really simple to fix but I am stumped. I have searched the web, all my books and this forum.
Any help is appreciated.

Oh... I guess I need help getting the values of the selection to be included into my sql statement... how do I dynamically include each selected date to pull and only those dates?

I am using sql server and vb.
 
Dim startdate as datetime
Dim enddate as datetime
Dim arrayDates() As String 'Your dates already populated, assuming they are in order from low to high
Dim intUpperBound as integer

intUpperBound = arrayDates.GetLength(intUpperBound)

startdate = arrayDates(0)
enddate = arrayDates(intUpperBound-1)

Dim strsql as string

strsql = "SELECT * FROM Calendar where date between '" & startdate & "' and '" & enddate & '"



is that what you need?
 
I have named the calendar CommunityCalendar
When i want a selected day I use CommunityCalendar.SelectedDate
If I want multiple days, I use CommunityCalendar.SelectedDates

What I was doing was taking CommunityCalendar.SelectedDate and putting that into my SQL statement... worked fine...
But when I changed it to SelectedDates it then said that the & was not a legal expression...

How can I take the SelectedDates and include that into the sql and have it work.
Here is a working statement:
MyCommand = New SQLCommand("Select diary.text_field,description,dte From diary Where diary.dte ='"& CommunityCalendar.SelectedDate &"' Order by diary.dte ASC", objconn)
Here is the non-working statement:
MyCommand = New SQLCommand("Select diary.text_field,description,dte From diary Where diary.dte ='"& CommunityCalendar.SelectedDates &"' Order by diary.dte ASC", objconn)

Why would it work for a single date and not for all dates???
It should already be an array, using that property... right??? unless I really dont' understand this control more than I thought I did.... And yes, this is my first time working with this control (can you tell?? :o )
 
You need to access the dates like kahlua001's reply, but keep in mind that SelectedDates is a collection, so do something like this...

Dim startDate As DateTime = Calendar1.SelectedDates.Item(0)
Dim endDate As DateTime = Calendar1.SelectedDates.Item(Calendar1.SelectedDates.Count - 1)

Then place startDate and endDate in your SQL statement.
 
Back
Top