C# 日历数据库模式的最佳实践?
我是C、ASP.NET、SQL Server Express和一般编程的初学者。我想在截止日期前制作一个在线日历。我会阅读所有其他类似的帖子,但现在我有一个问题,我希望这会让我走上正轨 将日历链接到数据库的步骤是什么?请举例说明在何处/如何做到这一点,我们将不胜感激C# 日历数据库模式的最佳实践?,c#,asp.net,calendar,C#,Asp.net,Calendar,我是C、ASP.NET、SQL Server Express和一般编程的初学者。我想在截止日期前制作一个在线日历。我会阅读所有其他类似的帖子,但现在我有一个问题,我希望这会让我走上正轨 将日历链接到数据库的步骤是什么?请举例说明在何处/如何做到这一点,我们将不胜感激 当一个日期由不同的用户输入多个条目时,我看到了可能的陷阱,因此如果有人知道如何再次管理,我会洗耳恭听。不知道这是否有帮助,但似乎有一些类似的解决方案我给您写了一个小例子,说明 连接到SQL 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);
}
祝你好运 我建议找几个免费的开源日历应用程序,看看它们的模式 而且两个看起来都有日历部分
你将有一个巨大的起跳,并将避免一些基本的错误。看起来有人已经问过这个问题了 建议使用整数字段而不是日期时间字段。他们会跑得更快。也不要害怕去规范化您的表。因此,您可能有一个日期列、年列、月列和日列