如何检查datagridview中的选定日期存在于数据库中 [英] How to check selected date in datagridview exists in database

查看:58
本文介绍了如何检查datagridview中的选定日期存在于数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注意它是windows应用程序。





假日原因(表名留下)



20/2/2013劳动节

25/2/2013假期



当我选择当月的日历所有日期都将使用csharp显示在datagridview中。



并且用户也无法在该月选择星期日。



对于上述两个条件我写了如下代码;

note it is windows application.


Holiday Reason(table Name Leave)

20/2/2013 Labour Day
25/2/2013 Holiday

When i select the calendar that month all dates will display in datagridview using csharp.

And also user did not able to select the sunday date in that month.

for the above two condition i written a code as follows;

DGVCalendar.Rows.Clear();
DateTime dt1 = Faculty_Available_Calendar.SelectionStart;
dt1 = new DateTime(dt1.Year, dt1.Month, 1);
DateTime dt2 = dt1.AddMonths(1);
int numDays = (dt2 - dt1).Days;
if (DGVCalendar.RowCount < numDays)
{
   DGVCalendar.RowCount = numDays;
}
int row = 0;
while (dt1 < dt2)
{
   DGVCalendar.Rows[row].Cells[1].Value = dt1.ToString("dd-MMM-yyyy");
   DGVCalendar.Rows[row].Cells[0].Value = true;  //All checkbox Checked Defaulty 

   if (dt1.DayOfWeek == DayOfWeek.Sunday)
   {
      DGVCalendar.Rows[row].ReadOnly = true;
      DGVCalendar.Rows[row].Cells[0].Value = false;
      DGVCalendar.Rows[row].Cells[0].Style.BackColor = Color.Orange;
      DGVCalendar.Rows[row].Cells[1].Style.BackColor = Color.Orange;
      DGVCalendar.Rows[row].Cells[2].Style.BackColor = Color.Orange;
      DGVCalendar.Rows[row].Cells[2].Value = "Sunday";
   }
   dt1 = dt1.AddDays(1);
   row++;
}



我想检查另一个条件,在datagridview中选择的日期出现在另一个表中。



如果用户使用复选框用户选择20/2/2013(datagridview中的上述日期),请选择20/2/2013日期显示消息不允许选择日期



因为该日期在休假表中。



如何验证。



请帮帮我。



我该怎么办,请帮帮我,我该怎么办,告诉我答案。



问候,

Narasiman P.



注意它是windows应用程序。


I want to check another condition selected date in datagridview is present in another Table.

if user select the 20/2/2013 (the above date in datagridview) using checkbox user select the 20/2/2013 Date shows the message "select date is not allowed"

Because that date is in Leave Table.

for that how to validate.

please help me.

How can i do,please help me,how can i do,tell me the answer.

Regards,
Narasiman P.

note it is windows application.

推荐答案

嗨专业

有很多方法可以做这个任务可能有人告诉你聪明的方式或某些不是那样但是根据我的逻辑,你有这个两个任务......



1.当用户选择第一个表的日期时,你必须在变量(sql查询)中取这个日期。



2.然后在第二个和主要任务中使用sql select with where =''" + your variable +"''conditon query你必须在secound表中读取那天如果得到HasRow = true或datareader dr.read()make true ...那么你必须最后弹出你的massegeDate Not Allowed..



你是否真的想与你分享......你有什么疑问下面的plz评论或者想要从我的结束然后的逻辑......但是第一次尝试从你的结束...



乐于助人
hi professional
there is many way to do this task may some one told you smart way or some one not that way but over all as per my logic for this you have two task...

1. when user select the date of 1st table then you have to take that date in a variable(sql query).

2. and in 2nd and main task then using sql select with where=''"+your variable+"'' conditon query you have to read that day in secound table and if get HasRow= true or datareader dr.read() make true...then you have to finally pop up your massege that "Date Not Allowed"..

Are you getting na that what actually i want to share with you....have any doubt plz comment below or want logic from my end then also...but 1st try from your end...

Happy to help


这篇关于如何检查datagridview中的选定日期存在于数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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