RocketGoal
RocketGoal

Reputation: 1553

Best Practices for a Calendar Database Schema?

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.

Upvotes: 4

Views: 6609

Answers (4)

Complex76
Complex76

Reputation:

Looks like someone already asked this question. Laying out a database schema for a calendar application

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.

Upvotes: 0

Alan Jackson
Alan Jackson

Reputation: 6511

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.

Upvotes: 0

user110714
user110714

Reputation:

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!

Upvotes: 1

Kostas Konstantinidis
Kostas Konstantinidis

Reputation: 13707

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

Upvotes: 1

Related Questions