locked
i have problems getting data from a access db to a dayrender RRS feed

  • Question

  • User651828378 posted

    Hi i have this code, where i get some dates from a db into a dayrender and then showing a calendar.
    But in getting an error about, where it cant find the tables !?
    Im new to this so i dont know what to look after.

    For Each dr In ds.Tables(0).Rows 


    My code is

        Dim ds As New DataSet
        Dim dsSelDate As DataSet
    
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Using connection As OleDbConnection = New OleDbConnection(ConfigurationManager.ConnectionStrings("ConnStr").ConnectionString)
                Using cmd As OleDbCommand = New OleDbCommand()
                    cmd.Connection = connection
                    cmd.CommandText = String.Format("SELECT * FROM event_cal")
                    Using adapter As OleDbDataAdapter = New OleDbDataAdapter(cmd)
                        Dim ds As New DataSet()
                        adapter.Fill(ds, "AllTables")
                        connection.Close()
                    End Using
                End Using
            End Using
    
            If Not IsPostBack Then
    
            End If
    
        End Sub
    
        'Day Render 
        Protected Sub DayRender(sender As Object, e As DayRenderEventArgs)
            If Not e.Day.IsOtherMonth Then
                Dim dr As DataRow
                For Each dr In ds.Tables(0).Rows
                    'If EventDate is not Null
                    If Not dr("event_date") Is DBNull.Value Then
                        Dim dtEvent As DateTime = dr("event_date").ToString
                        'If EventDate =CalendarDate
                        If dtEvent.Equals(e.Day.Date) Then
                            e.Cell.BackColor = Color.PaleVioletRed
                            e.Cell.BorderColor = System.Drawing.Color.Pink
                            e.Cell.Font.Italic = True
                            e.Cell.Font.Size = FontUnit.Large
                        End If
                    End If
                Next
                'If the month is not CurrentMonth then hide the Dates
            Else
                e.Cell.Text = ""
            End If
        End Sub



    Wednesday, June 27, 2012 8:30 AM

Answers

  • User3866881 posted

    For Each dr In ds.Tables(0).Rows

    You should check whether the "ds" has one DataTable at least....

    Try this——

    If(ds IsNot Nothing AndAlso ds.Tables.Count>0) Then
       For Each dr In ds.Tables(0).Rows
        'Do you logic here……
       Next
    End If
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 28, 2012 10:17 PM