Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6223531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:30:22+00:00 2026-05-24T08:30:22+00:00

I am currently using VB. I want to do a Calendar Control which have

  • 0

I am currently using VB. I want to do a Calendar Control which have dates highlighted/selected. All these dates are retrieved from a database.

First thing I need to know is how to put all the dates into an array
Second thing I need to know is how to highlight all the dates in the array.

I have done some research on the internet and they said something about selectedDates and selectedDates collection and dayrender. But frankly speaking, I can’t really find any VB codes regarding this. Dates format will be in dd/MM/yyyy

    Imports System.Data.SqlClient

    Partial Class _Default
Inherits System.Web.UI.Page

Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    Dim connectionString As String = ConfigurationManager.ConnectionStrings("CleanOneConnectionString").ConnectionString
    Dim connection As SqlConnection = New SqlConnection(connectionString)
    connection.Open()
    Dim sql As String = "Select schedule From OrderDetails Where schedule is not null"
    Dim command As SqlCommand = New SqlCommand(sql, connection)
    Dim reader As SqlDataReader = command.ExecuteReader()
    If (reader.Read()) Then
        If (reader.HasRows) Then
            While reader.Read()
                myCalendar.SelectedDates.Add(CType(reader.GetDateTime(0), Date))
            End While
        End If
    End If
    reader.Close()
    connection.Close()
    myCalendar.SelectedDayStyle.BackColor = System.Drawing.Color.Red
End Sub
    End Class

My Calendar

    <asp:Calendar ID="myCalendar" runat="server" ShowGridLines="True">
</asp:Calendar>

Updated with what I have done, but still does not show
Thanks for the help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T08:30:22+00:00Added an answer on May 24, 2026 at 8:30 am

    Assume you have a DataTable named myDates, and a Calendar control named myCalendar:

    For i As Int = 0 To myDates.Rows.Count - 1
        myCalendar.SelectedDates.Add(CType(myDates.Row(i)(0), Date)
    Next
    

    You can declare the highlighting in your markup:

    <asp:Calendar ID="myCalendar" runat="server">
        <SelectedDayStyle BackColor="red" />
    </asp:Calendar>
    

    Or programatically:

    myCalendar.SelectedDayStyle.BackColor = System.Drawing.Color.Red
    

    UPDATE For SqlDataReader (VB.NET this time)

    If reader.HasRows Then
        While reader.Read()
            myCalendar.SelectedDates.Add(CType(reader(0), Date)
        End While
    End If
    

    UPDATE based on OP’s code

    Are you getting any errors when the code runs? SqlDataReader.GetDateTime will throw an InvalidCastException if the column being read isn’t a DateTime column.

    I’m wondering if it’s a format issue? Can you verify the data type of the column in the database, as well as the format the date is being stored in?

    I’ve modified your code a bit with a couple of suggestons.

    Imports System.Data.SqlClient
    
    Partial Class _Default Inherits System.Web.UI.Page  
    
        Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    
            Dim connectionString As String = ConfigurationManager.ConnectionStrings("CleanOneConnectionString").ConnectionString
    
            ' Using blocks will automatically dispose of the object, and are 
            ' pretty standard for database connections
            Using connection As New SqlConnection(connectionString)
                connection.Open()     
                Dim sql As String = "Select schedule From OrderDetails Where schedule is not null"
                Dim command As SqlCommand = New SqlCommand(sql, connection)     
                Dim reader As SqlDataReader = command.ExecuteReader() 
    
                ' This is not needed - in fact, this line will "throw away"
                ' the first row in the row collection
                'If (reader.Read()) Then
    
                If (reader.HasRows) Then             
                    While reader.Read()
                        myCalendar.SelectedDates.Add(CType(reader.GetDateTime(0), Date))              End While         
                End If
    
                reader.Close()     
    
                ' Not needed because of the Using block
                'connection.Close()     
            End Using
    
            myCalendar.SelectedDayStyle.BackColor = System.Drawing.Color.Red 
        End Sub     
    End Class 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to read and write from serial using events/interrupts. Currently, I have it
I have a flash calendar from which I want to download the current screen
I'm currently using JTable to show the contents in database. I want to provide
Currently I'm using Fluent NHibernate to generate my database schema, but I want the
I'm currently developing an Android app, which loads events from a server using JSON
I have a String in which dates are there. I want this String to
I am currently using various back-end services and I want to use PHP to
This is weird, I am currently using iTextSharp and I want to add a
I want to pass a few variables to another page. Currently I'm using response.redirect
I want to add traffic information to my custom map. Currently I'm using a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.