如何使用数据读取器读取日期选择器 [英] How to read a datetimepicker with a datareader
问题描述
您好,
我正在申请不允许重复预订的应用程序,例如:
不能同时有2个约会.
Hi there
I am making an application which doesn''t allow double bookings , eg:
cannot have 2 appointments at the same time .
if (appointReader["AppointmentDate"] == dateTimePickerAppoint)
{
MessageBox.Show("Sorry, Appointment Date is Unavailable");
connect.Close();
}
我的SQL数据类型是datetime.
使用文本框,组合框等,以下工作有效,但不能使用datetimepicker进行工作,任何帮助将不胜感激.
My SQL data type is datetime.
With textboxes, comboboxes etc the following works but not with a datetimepicker , any help would be greatly appreciated .
if (appointReader["AppointmentId"].ToString() == textBoxAppointId.Text)
{
MessageBox.Show("this works");
connect.Close();
}
谢谢
Thank you
推荐答案
所以这不能正常工作吗?
So this isn''t working correctly?
if (appointReader["AppointmentDate"] == dateTimePickerAppoint)
如果是这样,几乎没有什么要检查的
-appointReader["AppointmentDate"]
的值是没有时间的日期,如果不是,则将时间信息存储在数据库中
-将Value
属性用于dateTimePickerAppoint
-dateTimePickerAppoint.Value
是否具有时间信息(如果有),如果只想处理日期,请将其删除
另外,您不需要数据库中的时间信息,请考虑将数据类型从datetime
更改为date
附带说明一下,如果connect
是数据库连接,我认为您应该在显示消息框之前将其关闭,以便尽快释放资源.
If so, few things to check
- is the value of appointReader["AppointmentDate"]
a date without time, if not you''re storing time information in the database
- use Value
property for dateTimePickerAppoint
- does the dateTimePickerAppoint.Value
have time information, if it does, remove it if you want to handle only dates
Also you don''t need time information in the database, consider changing the data type from datetime
to date
As a side note, if the connect
is the database connection, I think you should close it before you show the message box in order to release the resources as soon as possible.
这篇关于如何使用数据读取器读取日期选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!