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

the_sleeperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

the_sleeperAuthor Commented:
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

0
GreymanMSCCommented:
The Cell and Day properties  of the DayRenderingEventArg contain what you need.
 protected void calEventCalendar_DayRender(object sender, DayRenderEventArgs e)
    {
        // display events here...
        if (dsGetEvents != null) 
        { 
           // find the date
           datarow DayRow =dsGetEvents.Table(0).Rows.Find(e.Day.Date)
           if (DayRow != null)
           {
              //fill the cell, format it, et cetera.  
              //Play with the settings
              e.Cell.Text = R.Item("columnname").ToString
              
           }
        }
    }

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
GreymanMSCCommented:
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

0
the_sleeperAuthor Commented:
Thanks, GreymanMSC
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.