Link to home
Start Free TrialLog in
Avatar of the_sleeper
the_sleeperFlag for United States of America

asked on

C# Newbie HowTo: Wire a DataSet to a Calendar Control

Greetings,

I have created a dataset of events in a SQL Dbase. (See Code Sample). Now I'm trying to figure out how to wire it to the Calendar Control so as to have matching events display for the correct day. I've been all over the web looking for a good resource. Cant find any.

Please outline the steps I need to take and show a code example (for us "Greenhorns").

thanks
sleeper





using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Web;
 
/// <summary>
/// Summary description for calendarDataObject
/// </summary>
public class calendarDataObject
{
    // declare method to get events
	public DataSet getEvents()
	{
		// Step 01: Get conn string from web.config
        string CalConn = ConfigurationManager.ConnectionStrings["ConnectionString1"].ConnectionString;
 
        // Step 02: Test connection string
        if(CalConn != null)
        {
            // Step 03: Create a SqlConnection object
            SqlConnection objConn = new SqlConnection(CalConn);
 
            // Step 04: Create an SQL Query
            string qryGetEvents = "SELECT * FROM tbl_events";
 
            // Step 05: Create a SqlDataAdapter
            SqlDataAdapter sqlDA_getEvents = new SqlDataAdapter(qryGetEvents,CalConn);
 
            // Step 06: Create a dataset 
            DataSet dsGetEvents = new DataSet();
 
            // Step 07: Fill dataset
            sqlDA_getEvents.Fill(dsGetEvents);
 
            // Step 08: Return dataset
            return dsGetEvents;
        }
 
        // return null if no connection string present
        return null;
	}
}

Open in new window

Avatar of the_sleeper
the_sleeper
Flag of United States of America image

ASKER

Here is where im drawing a blank.

Getting an error stating that the DataSet (dsGetEvents) does not exist in the current context.

Little Help?

    protected void calEventCalendar_DayRender(object sender, DayRenderEventArgs e)
    {
        // display events here...
        if (dsGetEvents != null) 
        { 
         // do something
        }
    }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of GreymanMSC
GreymanMSC

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of GreymanMSC
GreymanMSC

Opps.  Obviously that R should have been the DayRow object, found by matching the primary key to the e.Day.Date.
e.Cell.Text = DayRow.Item("columnname").ToString

Open in new window

Thanks, GreymanMSC