Results 1 to 4 of 4

Thread: asp.net event calendar time display problem

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2005
    Posts
    3

    Red face asp.net event calendar time display problem

    Hi,

    I am trying to set on my intranet website an online event calendar using ASP.NET vb.net and an access 2000 database.

    Everything is working nicely since I can add new events,display and update them no problem.

    The only problem is that when displayed on the calendar, all the

    " event starting time" come in this format : 06/29/2005 7:30 Am

    when I only want the time to display on the 7:30 AM like format.Please help !

    You can find below my code :
    VB Code:
    1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    2. <%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" %>
    3. <%@ Import Namespace="System.Data" %>
    4. <%@ Import Namespace="System.Data.OleDb" %>
    5. <script runat="server">
    6.  
    7. Dim ds As New DataSet()
    8.  
    9. Protected Sub Page_Load(Src As [Object], E As EventArgs)
    10.    'Note: The following two lines of code should be on the same line.
    11.    Dim connectionstring As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("aspnet_calendar.mdb") + ";"
    12.    Dim sql As String = "select * from events"
    13.    
    14.    'Create a DataAdapter
    15.    Dim da As New OleDbDataAdapter(sql, connectionstring)
    16.    
    17.    'Fill the DataSet (ds)
    18.  
    19.    da.Fill(ds, "events")
    20. End Sub
    21.  
    22. Protected Sub eventscalendar_DayRender(Src As [Object], E As DayRenderEventArgs)
    23.    'use a StringBuilder object for optimized string concatenation
    24.    Dim strEvents As New StringBuilder()
    25.    strEvents.Append("<span style=""font-size:80%"">")
    26.    
    27.    Dim row As DataRow
    28.    For Each row In  ds.Tables("events").Rows
    29.       Dim eventdate As DateTime = CType(row("eventdate"), DateTime)
    30.       If eventdate.Equals(E.Day.Date) Then
    31.          
    32.          strEvents.Append(("<br />" + row("eventtext") + "<br />" + row("startingtime")))
    33.       End If
    34.    Next row
    35.    'Close off the string in the strEvents StringBuilder
    36.    strEvents.Append("</span>")
    37.    
    38.    'Add the string to the cell in a LiteralControl
    39.    E.Cell.Controls.Add(New LiteralControl(strEvents.ToString()))
    40. End Sub 'eventscalendar_DayRender
    41.  
    42. </script>
    43.  
    44. <html>
    45. <head>
    46. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    47. <title>Untitled Document</title>
    48. </head>
    49. <body>
    50. <form runat="server">
    51. <asp:calendar BackColor="#FFFFCC" DayHeaderStyle-BackColor="#FFFFFF" DayStyle-HorizontalAlign="right" Font-Size="16" Height="100%" ID="eventcalendar" NextPrevStyle-BackColor="#99FFCC" runat="server" ShowDayHeader="true" ShowGridLines="true" ShowNextPrevMonth="true" TitleFormat="MonthYear" TitleStyle-ForeColor="#0000FF" WeekendDayStyle-BackColor="#FFCCFF" Width="100%"
    52.   OnDayRender="eventscalendar_DayRender" align="center"></asp:calendar>
    53. </form >
    54.  
    55. </div>
    56. </body>
    57. </html>

  2. #2
    Junior Member Sami Antero's Avatar
    Join Date
    Jun 2005
    Location
    Helsinki, Finland
    Posts
    16

    Re: asp.net event calendar time display problem

    Hi! Your 'startingtime' in the db is probably as a Date. You could do a Cdate(row("startingtime")).ToShortTimeString . That would get you at least the short version extracted from the date stored. tsami
    Sami Antero
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    no smileys, no funky certificates. Sorry.

  3. #3

    Thread Starter
    New Member
    Join Date
    Jun 2005
    Posts
    3

    Re: asp.net event calendar time display problem

    Hi Sami,

    Thank you for your kind help but I'm getting now the following error message :
    "cast from type 'DBNull' to type 'Date' is not valid "

    For your information I've set 'startingtime' to DATE/TIME MEDIUM TIME format in my access database which should normally return 5:34 PM for instance
    so what's still wrong ?

    Maheother

  4. #4
    Junior Member Sami Antero's Avatar
    Join Date
    Jun 2005
    Location
    Helsinki, Finland
    Posts
    16

    Re: asp.net event calendar time display problem

    Hi again. I'll have to make a quess. The value you return from the db is interpreted as a System.DateTime and the Medium Time definition is ignored. This is ADO.NET OleDB's doings. I did found somethings related to this in http://www.dotnet247.com/247referenc..._discussions/7 . Hope this helps.

    tsami

    ps. I found this as well. MS says:
    Note: Using an Access (Jet) database as a data source for multithreaded applications, such as ASP.NET applications, is not recommended. If you must use Access as a data source for an ASP.NET application, and are unable to use an alternative such as SQL Server or MSDE, be aware that ASP.NET applications connecting to an Access database can encounter connection problems most commonly related to security permissions. For help troubleshooting connection problems using ASP.NET and an Access database, see article Q316675 "PRB: Cannot Connect to Access Database from ASP.NET" in the Microsoft Knowledge Base located at http://support.microsoft.com.
    Sami Antero
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    no smileys, no funky certificates. Sorry.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width