根据“日期/时间"类型字段过滤表 [英] Filtering a table based on a ‘Date/Time’ type field
本文介绍了根据“日期/时间"类型字段过滤表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,
我有一个在DataGridView控件中显示的表(在Access中).该表由一些字段组成,包括日期/时间"类型的文件,称为日期".我想根据此字段过滤表.尽管听起来微不足道,但它会引发一个错误,说:
查询表达式"Date = 2010/07/11 12:00:00 AM"中存在语法错误(缺少运算符).
我用下面的代码.您能告诉我代码有什么问题吗?
非常感谢
Hello,
I have a table (in Access) shown in a DataGridView Control. The table consists of some fields including a filed of the "Date/Time" type called "Date". I want to filter the table, based on this field. Although it sounds trivial, it raises an error saying that:
There is a syntax error (missing operator) in query expression "Date = 2010/07/11 12:00:00 AM".
I used the code below. Could you please let me know what is wrong with the code?
Thank you a lot
using System.Data.OleDb;
private void Form1_Load(object sender, EventArgs e)
{
string path = @"E:\Data\Myoffice\Access\";
string DataBase_Name = "MyDataBase.accdb";
string Table_Name = "Book";
string Sql_Comnd = "select * from " + Table_Name + " Where Date = 2010/07/11 12:00:00 AM";
OleDbConnection con = new OleDbConnection();
con.ConnectionString = con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source = " + path + DataBase_Name;
OleDbDataAdapter da = new OleDbDataAdapter( Sql_Comnd , con);
DataSet ds = new DataSet();
con.Open();
da.Fill(ds, Table_Name);
dataGridView1.DataSource = ds.Tables[Table_Name].DefaultView;
con.Close();
}
推荐答案
对于您的特定问题,请使用#
For your specific issue use a #
Where Date = #2010/07/11 12:00:00 AM#
除了明显的设计问题之外,我怀疑您的日期可能至少需要用引号引起来.
I suspect apart from the obvious design issues, that your date probably needs to be in quotes at least.
这篇关于根据“日期/时间"类型字段过滤表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文