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:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<script runat="server">
Dim ds As New DataSet()
Protected Sub Page_Load(Src As [Object], E As EventArgs)
'Note: The following two lines of code should be on the same line.
Dim connectionstring As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("aspnet_calendar.mdb") + ";"
Dim sql As String = "select * from events"
'Create a DataAdapter
Dim da As New OleDbDataAdapter(sql, connectionstring)
'Fill the DataSet (ds)
da.Fill(ds, "events")
End Sub
Protected Sub eventscalendar_DayRender(Src As [Object], E As DayRenderEventArgs)
'use a StringBuilder object for optimized string concatenation
Dim strEvents As New StringBuilder()
strEvents.Append("<span style=""font-size:80%"">")
Dim row As DataRow
For Each row In ds.Tables("events").Rows
Dim eventdate As DateTime = CType(row("eventdate"), DateTime)
If eventdate.Equals(E.Day.Date) Then
strEvents.Append(("<br />" + row("eventtext") + "<br />" + row("startingtime")))
End If
Next row
'Close off the string in the strEvents StringBuilder
strEvents.Append("</span>")
'Add the string to the cell in a LiteralControl
E.Cell.Controls.Add(New LiteralControl(strEvents.ToString()))
End Sub 'eventscalendar_DayRender
</script>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<form runat="server">
<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%"
OnDayRender="eventscalendar_DayRender" align="center"></asp:calendar>
</form >
</div>
</body>
</html>
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
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
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:
Quote:
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.