Click here to Skip to main content
15,921,577 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted

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


C#
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();
     }

}
 
Share this answer
 
Hi buddy..

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

C#
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();


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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900