Click here to Skip to main content
15,851,711 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Can anyone help I want to create an events calender that will retrieve the dates from the database and highlight those dates on the calender and when a user moves a mouse over that date the event pops up

i have a piece of code here but when i run it, it gives me an eror "Cannot find table 0"
i dnt know what is the problem.

Public Class Calender
Inherits System.Web.UI.Page
Protected dsHolidays As DataSet

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Calendar1.VisibleDate = DateTime.Today
FillHolidayDataset()
End Sub
Protected Sub FillHolidayDataset()
Dim firstDate As New DateTime(Calendar1.VisibleDate.Year, _
Calendar1.VisibleDate.Month, 1)
Dim lastDate As DateTime = GetFirstDayOfNextMonth()
dsHolidays = GetCurrentMonthData(firstDate, lastDate)
End Sub
Protected Function GetFirstDayOfNextMonth() As DateTime
Dim monthNumber, yearNumber As Integer
If Calendar1.VisibleDate.Month = 12 Then
monthNumber = 1
yearNumber = Calendar1.VisibleDate.Year + 1
Else
monthNumber = Calendar1.VisibleDate.Month + 1
yearNumber = Calendar1.VisibleDate.Year
End If
Dim lastDate As New DateTime(yearNumber, monthNumber, 1)
Return lastDate

End Function
Function GetCurrentMonthData(ByVal firstDate As DateTime, ByVal lastDate As DateTime) As DataSet
Dim dsMonth As New DataSet
Dim cs As ConnectionStringSettings

cs = ConfigurationManager.ConnectionStrings("ConnectionString1")
Dim connString As String = cs.ConnectionString
Dim dbConnection As New SqlConnection(connString)
Dim query As String
query = "SELECT N_date,msg FROM NotCalendar" & _
" WHERE N_date >= @firstDate AND N_date < @lastDate"
Dim dbCommand As New SqlCommand(query, dbConnection)
dbCommand.Parameters.Add(New SqlParameter("@firstDate", firstDate))
dbCommand.Parameters.Add(New SqlParameter("@lastDate", lastDate))
Dim sqlDataAdapter As New SqlDataAdapter(dbCommand)
Try
sqlDataAdapter.Fill(dsMonth)
Catch
End Try
Return dsMonth
End Function
Protected Sub Calendar1_DayRender(ByVal sender As Object, _
ByVal e As System.Web.UI.WebControls.DayRenderEventArgs) _
Handles Calendar1.DayRender
Dim nextDate As DateTime
If Not dsHolidays Is Nothing Then
For Each dr As DataRow In dsHolidays.Tables(0).Rows
nextDate = CType(dr("N_date"), DateTime)
If nextDate = e.Day.Date Then
e.Cell.BackColor = System.Drawing.Color.Pink
End If
Next
End If
End Sub

End Class
Posted
Updated 11-Oct-11 18:06pm
v3
Comments
Sergey Alexandrovich Kryukov 11-Oct-11 23:28pm    
It is not a valid question. There is not "it gives me an error". Catch an exception and provide exception dump with line numbers in the source code. Indicate these line numbers in your post. Format the code to look like code using the tag <pre lang="vb">...</pre>. Use "Improve question".
--SA

1 solution

You might be getting an error, but eating the exception in GetCurrentMonthData.

Try remove the try/catch, or at least throw the exception again, so you can see the error message:

Try
    sqlDataAdapter.Fill(dsMonth)
Catch
End Try
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900