两个日期之间的条件不匹配 [英] Criteria mismatched between two dates

查看:105
本文介绍了两个日期之间的条件不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它始终在条件表达式中显示条件不匹配。这是我的代码。

It always show criteria mismatch in criteria expression. Here's my code.

OleDbCommand pending = new OleDbCommand("SELECT * FROM businesses WHERE business_active = 0 AND date_of_application BETWEEN '" + FromDateTxt.Value.ToString("MM/dd/yyyy") + "' AND '" + ToDateTxt.Value.ToString("MM/dd/yyyy") + "'", cn.con);
        OleDbDataReader dr_pending = pending.ExecuteReader();


推荐答案

尝试以下操作,可以避免数据类型不匹配。如果您的列不仅是数据,则将参数设置为datatime:

Try the following, it avoids datatype mismatches. if your column is not only a data, make the parameter a datatime:

            SqlParameter fromDate = new SqlParameter();
            fromDate.ParameterName = "@FromDate";
            fromDate.SqlDbType = SqlDbType.Date;
            fromDate.Direction = ParameterDirection.Input;
            fromDate.Value = FromDateTxt.Value;

            SqlParameter toDate = new SqlParameter();
            toDate.ParameterName = "@ToDate";
            toDate.SqlDbType = SqlDbType.Date;
            toDate.Direction = ParameterDirection.Input;
            toDate.Value = ToDateTxt.Value;

            OleDbCommand pending = new OleDbCommand("SELECT * FROM businesses WHERE business_active = 0 AND date_of_application BETWEEN @FromDate AND @ToDate", cn.con);
            OleDbDataReader dr_pending = pending.ExecuteReader();

这篇关于两个日期之间的条件不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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