vb.net - Loading every day in a month from a database -


i'm creating calendar program can contain 6 events per day. software uses loop check everyday events. takes time opens , closes mysql connection 31 times. method works , takes 1 second per loop, im looking better method, if there one.

 integer = 1 31                 if (i = 32)                     exit                     main.hide()                    end if                  try                     dim reader mysqldatareader                     dim dbconn new mysqlconnection                     dim dbquery string = ""                     dim dbcmd new mysqlcommand                     dim dbadapter new mysqldataadapter                     dim dbtable new datatable                     dim count integer      if dbconn.state = connectionstate.closed                         dbconn.connectionstring = "database=###########;data source=###########;user id=###########;password=###########;connection timeout=20"                         dbconn.open()                     end if                     count = 0                     dbquery = "select * ########### date='" & numericmonth & "/" & & "/" & numericyear & "'"                       dbcmd                         .commandtext = dbquery                         .connection = dbconn                     end                     dbadapter                         .selectcommand = dbcmd                         .fill(dbtable)                     end                      '/// start event counter                      reader = dbcmd.executereader                     count = 0                     while reader.read                         count = count + 1                     end while                        '/////// if day contains 1 event                      if count = 1                         dim date1 = new customevent()                         dim bgcolor1 color = color.fromname(dbtable.rows(0).item(16).tostring())                         dim fontcolor1 color = color.fromname(dbtable.rows(0).item(17).tostring())                          '///event 1                          date1.ignoretimecomponent = true                         date1.eventtext = dbtable.rows(0).item(5).tostring()                         date1.date = numericyear & "," & numericmonth & "," &                         date1.recurringfrequency = recurringfrequencies.none                         date1.eventfont = new font("verdana", 12, fontstyle.regular)                         date1.eventcolor = bgcolor1                         date1.enabled = true                         calendar1.addevent(date1)                          '/// if day contains 2 events                           #####more events                          '/// if day contains 3 events                      elseif count = 3              #####more events                          '/// if day contains 4 events                      elseif count = 4                          #####more events                          '/// if day contains 5 events                      elseif count = 5                          #####more events                          '/// if day contains 6 events                      elseif count = 6              #####more events                      end if                    catch ex exception                     messagebox.show("a database error has occured" & vbcrlf & vbcrlf & ex.message & vbcrlf & _                                 vbcrlf + "please report it/systems helpdesk @ ext 8888.")                     application.exit()                  end try                 main.progressbar1.value = main.progressbar1.value + 3              next         else         end if 


Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -