views:

831

answers:

4

I'm a beginner with C#, ASP.NET, SQL Server Express and programming in general. I'm trying to make an online calendar (on a deadline). I'll read all the other posts that are similar to this, but for now I have a question that I hope will set me on my way.

What are the steps to link a calendar to a database? Any examples of where/how this has been done would be greatly appreciated?

I see possible pitfalls when a date has more than one entry by different users, so if anyone knows how this is managed again I'm all ears.

+1  A: 

Dunno if this is of any help but CodeProject seems to have some similar solution

Konstantinos
Thanks. I'll get stuck in to reading their example
Mike
+1  A: 

I have wrote you a small example that shows

  1. Connecting to a SQL Express server
  2. Reading data
  3. Selecting multiple dates (i.e. more than one date entry by different users)

Hope this helps!...

// The SQL connection object to connect to the database. Takes connection string.
SqlConnection connection = 
    new SqlConnection(@"Data Source=localhost\SQLEXPRESS;Initial Catalog=Example");

// Idealy you wouldnt pass direct SQL text for injection reasons etc, but
// for example sake I will enter a simple query to get some dates from a table.
// Notice the command object takes our connection object...
SqlCommand command = new SqlCommand("Select [Date] From Dates", connection);

// Open the connection
connection.Open();

// Execute the command
SqlDataReader reader = command.ExecuteReader();

// A list of dates to store our selected dates...
List<DateTime> dates = new List<DateTime>();

// While the SqlDataReader is reading, add the date to the list.
while (reader.Read())
{
    dates.Add(reader.GetDateTime(0));
}

// Close the connection!
connection.Close();

// Use the selected dates property of the ASP.NET calendar control, add every
// date that we read from the database...
foreach (DateTime date in dates)
{
    Calendar1.SelectedDates.Add(date);
}

Good luck!

Chalkey
A: 

I'd recommended finding a couple of free open source calendar applications and looking at their schemas.

MojoPortal and DotNetNuke Events both look like they have calendar portions.

You'll have a huge jump start and will avoid some basic mistakes.

Alan Jackson
A: 

Looks like someone already asked this question. http://stackoverflow.com/questions/947272/laying-out-a-database-schema-for-a-calendar-application/947322

One word of advice is to use integer fields instead of datetime fields. They will run faster. Also don't be afraid to denormalize your tables. So you might have a date column, year column, month column, and day column.

Complex76