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

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

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

当一个日期由不同的用户有多个条目时,我看到可能存在的陷阱,所以如果有人知道如何再次管理这个,我就全都听见了.

最佳答案 我给你写了一个小例子

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

希望这可以帮助!…

// 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);
}

祝好运!

点赞