我很有意思。看了很多论坛,但没有找到。在VB 2010 MS访问查询涉及日期范围
我试图使用VB 2010 System.Data.OleDb对象从Access数据库查询数据。 下面是代码:
Dim AccessCommand As New System.Data.OleDb.OleDbCommand("SELECT format(dateadd(""m"", -e.tenure, e.expirydate), ""yyyy-mm-dd"") as Expired, n.customerid , e.type as Description, (select s.type from servicetype s where s.servicecode = e.servicecode) as CodedType, (select v.servicecode from servicetype v where v.servicecode = e.servicecode) as ServiceCode, e.totalamount INTO [Excel 12.0 Xml;DATABASE=d:\BookTest.xlsx;HDR=Yes;].[Sheet1] " _
& " From notification n, notificationservice e where " _
& " e.notificationid = n.notificationid " _
& " and mid(n.notificationid, 1,2) ='RN' " _
& " and jn_duplicate = 0 " _
& " and dateadd(""m"", -e.tenure, e.expirydate) between @1 and @2 " _
& " and (n.salesid is null or (n.salesid is not null and not exists
(select paymentid from payment p where p.invoiceid = n.salesid))) ", _
m_conn)
AccessCommand.Parameters.Add("@1", OleDbType.Date).Value = New DateTime(2013, 7, 21) '"#20-jul-2013#" '(InputBox("Enter Expiry DateFrom in dd-mon-yyyy", "", "", 100, 100))
AccessCommand.Parameters.Add("@2", OleDbType.Date).Value = New DateTime(2013, 7, 31) '"'#30-jul-2013#" '(InputBox("Enter Expiry DateTo in dd-mon-yyyy", "", "", 100, 100))
但是,像指定等没有数据尝试尽可能多的组合,我总是得到错误..
我的目标是让用户键入两个日期,将形成日期从和日期到在查询之间有日期。
将不胜感激任何帮助。
感谢 卓
“...错误就像没有指定的数据等”有点不清楚,你能发布确切的错误信息吗? –
错误是“没有给出一个或多个所需参数的值”。这个错误被我包含的异常捕获所困住。 –