如何查询where和between子句中的DBF(dbase)文件日期类型字段 [英] how to query DBF(dbase) files date type field in where and between clause
问题描述
我有一个DBF文件,我正在尝试从c#代码中读取它。我可以成功读取文件,而无需对varchar类型字段应用任何条件或应用条件。我的问题是我必须从Date字段(type:date)中过滤记录。我尝试了以下方法,
I have a DBF file and I'm trying read it from c# code. I can read files successfully without applying any conditions or applying conditions for varchar type fields.My problem is I have to filter the records from the Date field (type:date). I have tried following ways,
SELECT * FROM D:\DBFreader\file.dbf where [RDATE] between 2/16/2006 12:00:00 AM and 2/20/2006 12:00:00 AM
上面给出了一个语法错误:缺少运算符
above gives a syntax Error: missing operator
SELECT * FROM D:\DBFreader\file.dbf where [RDATE] between '2/16/2006 12:00:00 AM' and '2/20/2006 12:00:00 AM'
上面给出了数据类型不匹配错误
above gives a data type mismatch error
SELECT * FROM D:\DBFreader\file.dbf where [RDATE] between 2/16/2006 and 2/20/2006
where子句也发生同样的情况。
我该怎么做才能从某个范围中过滤记录
The same things happens for the where clause as well. What can I do to filter records from a range
我正在使用以下代码对其进行读取
I'm using following code to read it
OdbcCommand cmd = new OdbcCommand();
OdbcDataAdapter da = new OdbcDataAdapter();
DataTable dt = new DataTable();
using (OdbcConnection connection = new OdbcConnection(connstring))
{
connection.Open();
cmd = new OdbcCommand(@"SELECT * FROM D:\DBFreader\file.dbf where [RDATE] between 2/16/2006 12:00:00 AM and 2/20/2006 12:00:00 AM", connection);
cmd.CommandType = CommandType.Text;
da.SelectCommand = cmd;
da.Fill(dt);
}
推荐答案
确定-
我相信问题是dBase / xBase不支持SQL日期之间的之间
I believe the problem is that dBase/xBase doesn't support "between" for SQL dates
WORKAROUND:
WORKAROUND:
@ SELECT * FROM D:\DBFreader\file.dbf,其中[RDATE]> =#2/16/2006 12:00: 00 AM#和[RDATE]<#2/20/2006 12:00:00 AM#
PS:
我知道dBase语法支持日期字面量(例如 2/16/2006;我不知道日期时间-请尝试看看。
PS: I know dBase syntax supports "date" literals (e.g. "2/16/2006"; I don't know about "datetime" - plese try it and see.
这篇关于如何查询where和between子句中的DBF(dbase)文件日期类型字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!