日历数据库架构的最佳实践?

时间:2009-06-30 08:49:54

标签: c# asp.net calendar

我是C#,ASP.NET,SQL Server Express和一般编程的初学者。我正在尝试制作在线日历(截止日期)。我会阅读所有其他与此类似的帖子,但现在我有一个问题,希望能帮我上路。

将日历链接到数据库的步骤是什么?任何在何处/如何做到这一点的例子将不胜感激?

当一个日期由不同用户输入多个条目时,我发现可能存在陷阱,所以如果有人知道如何再次管理这个问题,我会全力以赴。

4 个答案:

答案 0 :(得分:1)

Dunno如果这有任何帮助,但CodeProject似乎有一些类似的解决方案

答案 1 :(得分:1)

我给你写了一个显示

的小例子
  1. 连接到SQL Express服务器
  2. 阅读数据
  3. 选择多个日期(即不同用户输入多个日期)
  4. 希望这有帮助!...

    // 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);
    }
    
    祝你好运!

答案 2 :(得分:0)

我建议找一些免费的开源日历应用程序并查看他们的模式。

MojoPortalDotNetNuke Events 看起来都有日历部分。

你将有一个巨大的启动,并将避免一些基本的错误。

答案 3 :(得分:0)

看起来有人已经问过这个问题。 Laying out a database schema for a calendar application

一个建议是使用整数字段而不是datetime字段。他们会跑得更快。也不要害怕对表格进行反规范化。因此,您可能有日期列,年份列,月份列和日期列。