Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. how to highlight dates of Month Calendar from database windows form

how to highlight dates of Month Calendar from database windows form

Scheduled Pinned Locked Moved Visual Basic
databasequestionsecuritytutorial
8 Posts 4 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Meax
    wrote on last edited by
    #1

    Dim DateAsString As New ArrayList this is the part i am using in form load to get all the dates for the Meeting. private sub getalldate() Dim connectionString As String = "Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=MyDB;Data Source=192.168.0.8" Dim connection As SqlConnection = New SqlConnection(connectionString) connection.Open() Dim sql As String = "SELECT MeetingDate FROM Meetings" 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() dateasstring.Add("#" & reader(0) & "#") End While End If End If reader.Close() connection.Close() end sub private sub makedatesboldincalendar() Dim num As Date Dim dtArrSpecialDates() As Date For Each num In dateasstring dtArrSpecialDates = {num} MonthCalendar1.BoldedDates = dtArrSpecialDates Next end sub what happens is it makes date bold but only the last date it is getting from database. there are more than 10 entries in the Meetings table. so, how can i highligh all the dates i am getting from database?

    L Richard DeemingR 2 Replies Last reply
    0
    • M Meax

      Dim DateAsString As New ArrayList this is the part i am using in form load to get all the dates for the Meeting. private sub getalldate() Dim connectionString As String = "Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=MyDB;Data Source=192.168.0.8" Dim connection As SqlConnection = New SqlConnection(connectionString) connection.Open() Dim sql As String = "SELECT MeetingDate FROM Meetings" 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() dateasstring.Add("#" & reader(0) & "#") End While End If End If reader.Close() connection.Close() end sub private sub makedatesboldincalendar() Dim num As Date Dim dtArrSpecialDates() As Date For Each num In dateasstring dtArrSpecialDates = {num} MonthCalendar1.BoldedDates = dtArrSpecialDates Next end sub what happens is it makes date bold but only the last date it is getting from database. there are more than 10 entries in the Meetings table. so, how can i highligh all the dates i am getting from database?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      The first port of call should be MonthCalendar.BoldedDates Property (System.Windows.Forms)[^] where it explains that each call to BoldedDates will clear any previously set.

      M 1 Reply Last reply
      0
      • L Lost User

        The first port of call should be MonthCalendar.BoldedDates Property (System.Windows.Forms)[^] where it explains that each call to BoldedDates will clear any previously set.

        M Offline
        M Offline
        Meax
        wrote on last edited by
        #3

        how can I make all the dates thats coming from the database as bold in the calendar?

        L 1 Reply Last reply
        0
        • M Meax

          how can I make all the dates thats coming from the database as bold in the calendar?

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Read the documentation and implement your code in the way shown.

          1 Reply Last reply
          0
          • M Meax

            Dim DateAsString As New ArrayList this is the part i am using in form load to get all the dates for the Meeting. private sub getalldate() Dim connectionString As String = "Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=MyDB;Data Source=192.168.0.8" Dim connection As SqlConnection = New SqlConnection(connectionString) connection.Open() Dim sql As String = "SELECT MeetingDate FROM Meetings" 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() dateasstring.Add("#" & reader(0) & "#") End While End If End If reader.Close() connection.Close() end sub private sub makedatesboldincalendar() Dim num As Date Dim dtArrSpecialDates() As Date For Each num In dateasstring dtArrSpecialDates = {num} MonthCalendar1.BoldedDates = dtArrSpecialDates Next end sub what happens is it makes date bold but only the last date it is getting from database. there are more than 10 entries in the Meetings table. so, how can i highligh all the dates i am getting from database?

            Richard DeemingR Offline
            Richard DeemingR Offline
            Richard Deeming
            wrote on last edited by
            #5

            Don't use ArrayList; use List<DateTime>. Don't convert the dates to strings; keep them as DateTime. Don't loop over the array setting the BoldedDates for each element; just set the BoldedDates to the list of dates. Don't call .Read before testing whether the data reader has any rows; you're skipping the first row.

            Private AllDates As DateTime()

            Private Sub GetAllDate()
            'TODO: Load the connection string from the configuration file
            Const connectionString As String = "Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=MyDB;Data Source=192.168.0.8"
            Const sql As String = "SELECT MeetingDate FROM Meetings"

            Using connection As New SqlConnection(connectionString)
                connection.Open()
                
                Using command As New SqlCommand(sql, connection)
                    Using reader As SqlDataReader = command.ExecuteReader()
                        Dim dates As New List(Of DateTime)()
                        
                        While reader.Read()
                            dates.Add(reader.GetDateTime(0))
                        End While
                        
                        AllDates = dates.ToArray()
                    End Using
                End Using
            End Using
            

            End Sub

            Private Sub MakeDatesBoldInCalendar()
            MonthCalendar1.BoldedDates = AllDates
            End Sub


            "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

            "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

            M 1 Reply Last reply
            0
            • Richard DeemingR Richard Deeming

              Don't use ArrayList; use List<DateTime>. Don't convert the dates to strings; keep them as DateTime. Don't loop over the array setting the BoldedDates for each element; just set the BoldedDates to the list of dates. Don't call .Read before testing whether the data reader has any rows; you're skipping the first row.

              Private AllDates As DateTime()

              Private Sub GetAllDate()
              'TODO: Load the connection string from the configuration file
              Const connectionString As String = "Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=MyDB;Data Source=192.168.0.8"
              Const sql As String = "SELECT MeetingDate FROM Meetings"

              Using connection As New SqlConnection(connectionString)
                  connection.Open()
                  
                  Using command As New SqlCommand(sql, connection)
                      Using reader As SqlDataReader = command.ExecuteReader()
                          Dim dates As New List(Of DateTime)()
                          
                          While reader.Read()
                              dates.Add(reader.GetDateTime(0))
                          End While
                          
                          AllDates = dates.ToArray()
                      End Using
                  End Using
              End Using
              

              End Sub

              Private Sub MakeDatesBoldInCalendar()
              MonthCalendar1.BoldedDates = AllDates
              End Sub


              "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

              M Offline
              M Offline
              Meax
              wrote on last edited by
              #6

              i have managed to do it. but really appreciate that you have explained so well and gave code too. hopefully some other user will find it useful. thank you.

              M 1 Reply Last reply
              0
              • M Meax

                i have managed to do it. but really appreciate that you have explained so well and gave code too. hopefully some other user will find it useful. thank you.

                M Offline
                M Offline
                Mycroft Holmes
                wrote on last edited by
                #7

                Psst to thank him properly up vote the answer - arrows appear top left of the answer box.

                Never underestimate the power of human stupidity RAH

                M 1 Reply Last reply
                0
                • M Mycroft Holmes

                  Psst to thank him properly up vote the answer - arrows appear top left of the answer box.

                  Never underestimate the power of human stupidity RAH

                  M Offline
                  M Offline
                  Meax
                  wrote on last edited by
                  #8

                  have clicked the green arrow :)

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups