如何检查数据库中的选择日期不要使用csharp选择(如何验证) [英] How to check select date in database dont select(how to validate) using csharp

查看:97
本文介绍了如何检查数据库中的选择日期不要使用csharp选择(如何验证)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请注意,它是Windows应用程序。





Access中的数据库设计如下



员工姓名文字

主题文字

日文





在数据库中记录如下。



员工休假详情(表名StaffLeaveDetails)



工作人员姓名主题日



Ram Eng星期三

Sam Tam星期二

Gopi Mat星期五

Ram Eng星期四

Magesh Sci星期五

Gopi Eng星期六



另一个数据库设计如下i女士访问



表名(员工可用性)



员工姓名文本

日期日期时间





员工可用性a bove两个字段正在保存在数据库中。



我的设计屏幕如下。





员工姓名组合框(在该组合框中,所有员工姓名检索到StaffLeaveDetails表并显示在组合框中)



Desing Screen

员工姓名组合框

日历(月历)

日期文本框。





当我从组合框中选择员工姓名并从日历中选择日期时,所选日期显示在文本框中。





我想检查StaffLeaveDetails表中Partiuclar Staff Name的选定日期,如果存在日期显示消息选择不同的日期。



为什么我可以验证。我怎么能用csharp。



请帮帮我。



关心&谢谢,

Narasiman P.





注意这是风应用程序。

Note it is windows application.


Database design as follows in Ms Access

Staff Name Text
Subject Text
Day Text


Records in the database as follows.

Staff Leave Details (table name StaffLeaveDetails)

Staff Name Subject Day

Ram Eng Wednesday
Sam Tam Tuesday
Gopi Mat Friday
Ram Eng Thursday
Magesh Sci Friday
Gopi Eng Saturday

Another Database design as follows i Ms Access

Table Name (Staff Availability)

Staff Name Text
Date Date Time


In the Staff Availability above two fields are saving in the database.

My Design Screen as follows.


Staff Name Combo Box(in that combo box all staff name retrieved StaffLeaveDetails table and display in to the Combo Box)

Desing Screen
Staff Name Combobox
Calendar (month Calendar)
Date Textbox.


When i select the Staff Name from the Combo box and select the Date from the calendar that selected date is display in the textbox.


I want to check the selected Date exists for Partiuclar Staff Name in the StaffLeaveDetails table, if date exists show the message "Select Different Date".

for that how can i validate.How can i do using csharp.

please help me.

Regards & Thanks,
Narasiman P.


Note it is windows application.

推荐答案

hi,

使用datetimepicker控件的leave事件。并按照以下编码。






use leave event of datetimepicker control. and follow the below coding.


private void dateTimePicker1_Leave(object sender, EventArgs e)
{
     String query;
     query="Select StaffName from staffAvailability where StaffNAme='" + selectedstaffname + "'";
     query += " and date='" + selecteddatetime.tostring("MM/dd/yyyy") + "'"      
     
     //u can modify as which date format using.
     
     //open connection string and execute the above query. for an example i am using datable

     if (dt.RowsCount>0)
     {
          messageBox.show ("Select Different Date");
          dateTimePicker1.Focus();
     }

}


嗨哥们..



根据您的要求,此代码可以帮助您...



Hi buddy..

as per you requirement may this code help you...

string query="select Staff Name from StaffLeaveDetails where date ='"textbox1.text"'  "; 
con.open()
SqlCommand cmd=new sqlcommand(con,query)
sqlDataReader dr=cmd.executeReader(); 

if(dr.read())
{
messageBox.show("Select different Date for this staff");
}
else
{
messageBox.show("This staff is free on this date");
}
con.close();





条件为真但只是看看Sql连接程序..但总的来说,如果有任何问题评论,请帮助你好友PLZ



乐于助人



condition is true but just take a look on Sql connection procedure..but overall it helps you buddy if any problem comment below plz

Happy to help


这篇关于如何检查数据库中的选择日期不要使用csharp选择(如何验证)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆