college_amy Posted December 23, 2004 Posted December 23, 2004 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. Quote
kahlua001 Posted December 30, 2004 Posted December 30, 2004 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? Quote
college_amy Posted January 3, 2005 Author Posted January 3, 2005 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 ) Quote
Moderators Robby Posted January 3, 2005 Moderators Posted January 3, 2005 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. Quote Visit...Bassic Software
college_amy Posted January 3, 2005 Author Posted January 3, 2005 THANK YOU Kahlua and Robby... It is now working. You guys rock!! Amy Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.