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 8489889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:57:10+00:00 2026-06-10T21:57:10+00:00

I need to highlight the dates in a MonthCalendar depending on the data I

  • 0

I need to highlight the dates in a MonthCalendar depending on the data I get from a database, but it keeps throwing me an OutOfMemory exception. I get the days which I have to highlight from database as bool values like this:

command.CommandText = "SELECT Monday FROM Days WHERE Event = "+idEvent+"";
Monday = Convert.ToBoolean(command.ExecuteScalar());

Similar code is used for each day of the week. The range in which I have to highlight the dates is entire year (start and end are the first and the last day of the year, both of DateTime type). I tried to do it with this code:

for (DateTime day = start; day < end; day.AddDays(1))
            {
                if (Monday && day.DayOfWeek == DayOfWeek.Monday)
                {
                    dates.Add(day);
                }
                else if (Tuesday && day.DayOfWeek == DayOfWeek.Tuesday)
                {
                    dates.Add(day);
                }
                else if (Wednesday && day.DayOfWeek == DayOfWeek.Wednesday)
                {
                    dates.Add(day);
                }
                else if (Thursday && day.DayOfWeek == DayOfWeek.Thursday)
                {
                    dates.Add(day);
                }
                else if (Friday && day.DayOfWeek == DayOfWeek.Friday)
                {
                    dates.Add(day);
                }
                else if (Saturday && day.DayOfWeek == DayOfWeek.Saturday)
                {
                    dates.Add(day);
                }
                else if (Sunday && day.DayOfWeek == DayOfWeek.Sunday)
                {
                    dates.Add(day);
                }
            }
            monthCalendar1.BoldedDates = dates.ToArray();

The point of this algorithm is to bold the dates on which the selected event occurs (every event occurs periodically entire year, with some exceptions like holidays or some specific time interval). So for each event there could be over 200 occurrences a year. How can I solve this problem?

  • 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-06-10T21:57:12+00:00Added an answer on June 10, 2026 at 9:57 pm

    One possible reason is that your iteration code is faulty in that day.AddDays(1) does not operate in place. it returns a new DateTime on which the operation has been done.

    Therefore the value of day never changes and your loop is running infinitely.

    Use a while loop instead:

    DateTime day = start;
    while (day < end)
    {
        // your date checking logic
    
        day = day.AddDays(1);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have searched the database but need to specifically sum(of hours flown or days off)in
I need to highlight changes(diff) between 2 database text fields in a asp.net application.
In a table I have columns with to and from dates, I highlight overlaps
I need to highlight each word separately from a string, even if the string
I need to highlight line with caret in NSTextView using CALayer overlay and grab
I'm programming an application in Struts and I need to highlight some reminders in
I have a regular texbox control. I need to highlight some words with a
I need to find text in html and highlight that html without corrupting html
I need to be able do the following on a TR: onmouseover highlight the
i need to get number of order highlighted element (by javascript, jquery): <li>A</li> <li>B</li>

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.