它始终在条件表达式中显示条件不匹配。这是我的代码。
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();
答案 0 :(得分:1)
请尝试以下操作,它可以避免数据类型不匹配。如果您的列不仅是数据,请将参数设置为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();