我试过的条件表达式中的数据类型不匹配但它不起作用 [英] Datatype mismatch in criteria expression i tried but it is not working

查看:82
本文介绍了我试过的条件表达式中的数据类型不匹配但它不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Access中的数据库结构如下



Database Strucure as follows in Ms Access

fieldname   Datatype 
Hokiday     Datetime
Reason      Text





假期原因(表名留下)在Ms Access

20/2/2013劳动节

25/2/2013假日



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



并且用户也无法选择那个月的星期日。



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







Holiday Reason (table Name Leave) In Ms Access
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; 
 
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中选择的日期出现在另一个表中。



如果用户选择2013年2月20日(datagridview中的上述日期)

使用复选框用户选择20/2/2013日期,

显示消息不允许选择日期



因为离职表中的日期为20/2/2013。



对于上述条件,我编写如下代码;




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 the date 20/2/2013 is present in the Leave Table.

For the above condition i written the code as follows;

sql = "select Reason from Leave where Holidaydate = '" +   DGVCalendar.Rows[row].Cells[1].ToString() + "'";
               OleDbCommand cmd = new OleDbCommand(sql, GFun.OleDbCon);
               OleDbDataReader dr = cmd.ExecuteReader();
               if (dr.Read())
               {
                   DGVCalendar.Rows[row].Cells[1].Style.BackColor = Color.Blue;
                   DGVCalendar.Rows[row].Cells[2].Value = dr[0].ToString();
               }



因为该日期在休假表中。



当我运行显示错误如下;



标准表达式中的数据类型不匹配。



来自我上面的那个条件我犯了什么错误。





请帮帮我。



问候,

Narasiman P


Because that date is in Leave Table.

When i run shows error as follows;

Data type mismatch in criteria expression.

from my above in that condition what is the mistake i made.


Please help me.

Regards,
Narasiman P

推荐答案

日期必须用''#''字符分隔:1 feb 2013 =#2 / 1/2013#。

另请注意,格式为mm / dd / yyyy。



参见这篇文章了解更多详情。



干杯
Dates must be delimited by ''#'' characters : 1 feb 2013 = #2/1/2013#.
Also note that the format is mm/dd/yyyy.

See this article for more details.

Cheers


这篇关于我试过的条件表达式中的数据类型不匹配但它不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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