如何使用乘法条件查询访问数据库 [英] How to quering access db with multiply conditions
本文介绍了如何使用乘法条件查询访问数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的代码流畅,我想从表'notes'中选择两种类型的单词'Checked In'和'Checked Out',通过过滤日期,但它不起作用,请帮助。
My codes are flowing, i want to select two types words 'Checked In' and 'Checked Out' from table 'notes', by filtering with date, but it's not working, please help.
SELECT (LedgersName) as [Ledgers Name], (TransDate) as [Date], (Total) as [Total], (TotalPaid) as [Total Paid], (Balence) as [Balence], (Notes) as [Notes], (LedgersID) as [Ledgers ID], (TransID) as [Trans ID] from MasterTrans where Notes='Checked In' or Notes='Checked Out' and TransDate between #" & dtpForm.Value.Date & "# And #" & dtpTo.Value.Date & "#
SHOUTING已删除 - OriginalGriff [/ edit]
[edit]SHOUTING removed - OriginalGriff[/edit]
推荐答案
请阅读我对这个问题的评论。
第一眼看你的查询看起来不错,但是..我建议:
1)删除字段名称周围的(
和)
括号,
2)添加参数 [ ^ ],
3)通过DateTimePicker控件传递给查询的检查值。
Please, read my comment to the question.
On the first look your query looks OK, but.. i suggest to:
1) remove(
and)
brackets around field names,
2) add parameters[^],
3) check value passed to query through DateTimePicker control.
PARAMETERS [dateFrom] DATE, [dateTo] DATE;
SELECT LedgersName as [Ledgers Name], TransDate as [Date], Total as [Total], TotalPaid as [Total Paid], Balence as [Balence], Notes as [Notes], LedgersID as [Ledgers ID], TransID as [Trans ID]
FROM MasterTrans
WHERE (Notes='Checked In' OR Notes='Checked Out') AND TransDate Between [dateFrom] And [dateTo];
然后使用 OleDbCommand的 [ ^ ]与 OleDbParameters.AddWithValue [ ^ ]方法。
请注意,请勿使用 Access 2002和更高版本的Access中的保留字列表 [ ^ ]
Then call this query using OleDbCommand[^] together with OleDbParameters.AddWithValue[^] method.
Be aware, don't use List of reserved words in Access 2002 and in later versions of Access[^]
您的访问查询应该是这个
Your access query should like this
SELECT Db_Manager.DbName, Db_Manager.Description
FROM Db_Manager where createddate between
#13/07/2014# and #15/07/2014#
和C#
and in C#
SELECT Db_Manager.DbName, Db_Manager.Description
FROM Db_Manager where createddate between
'#' + " & dtpForm.Value.Date & " + '#' and '#' + " & dtpTo.Value.Date & + " + '#'
这篇关于如何使用乘法条件查询访问数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文