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

标签 c# asp.net calendar

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

将日历链接到数据库的步骤是什么?如果能举出在何处/如何完成此操作的任何示例,我们将不胜感激?

当一个日期有多个不同用户输入时,我发现可能存在陷阱,所以如果有人知道如何再次管理它,我会洗耳恭听。

最佳答案

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

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

祝你好运!

关于c# - 日历数据库架构的最佳实践?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1062527/

相关文章:

c# - 在 C# 中读取并发送 mp4 文件

c# - 通用方法,是否可以返回 StreamReader 实例?

c# - 如何处理动态对象中带有特殊字符的字段?

c# - 如何在 ASP.NET MVC 中更改 int 模型验证的 ErrorMessage?

ASP.NET Identity - 关于 [Authorize] 和 RoleManager 的混淆

java - 如何检查 date 中的变量是否比当前日期早 10 秒

c# - 如何统一生成JSON字符串?

asp.net - HttpUtility.UrlEncode() 和 Server.UrlEncode() 未对 asp.net 4.0 中的 URL 进行编码

Java Date 判断 DAY 是否大于

python - 即使在 Windows 10 中使用 pip 安装了 KivyCalendar,也会收到错误 : No module named 'calendar_ui' .