【问题标题】:Best Practices for a Calendar Database Schema?日历数据库模式的最佳实践?
【发布时间】:2010-11-06 22:41:36
【问题描述】:

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

将日历链接到数据库的步骤是什么?任何有关在何处/如何完成此操作的示例将不胜感激?

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

【问题讨论】:

    标签: c# asp.net calendar


    【解决方案1】:

    我给你写了一个小例子来说明

    1. 连接到 SQL Express 服务器
    2. 读取数据
    3. 选择多个日期(即不同用户输入多个日期)

    希望这会有所帮助!...

    // 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】:

      不知道这是否有帮助,但CodeProject 似乎有一些类似的解决方案

      【讨论】:

        【解决方案3】:

        我建议找到几个免费的开源日历应用程序并查看它们的架构。

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

        你会有一个巨大的起点,并且会避免一些基本的错误。

        【讨论】:

          【解决方案4】:

          好像有人已经问过这个问题了。 Laying out a database schema for a calendar application

          一个建议是使用整数字段而不是日期时间字段。他们会跑得更快。也不要害怕去规范化你的表格。所以你可能有一个日期列、年份列、月份列和日期列。

          【讨论】:

            猜你喜欢
            • 2012-11-20
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2012-09-16
            • 1970-01-01
            • 2011-10-03
            • 1970-01-01
            相关资源
            最近更新 更多