我束手无策。看了很多论坛但没有找到。
我正在尝试使用 VB 2010 System.Data.OleDb 对象从 Access db 查询数据。下面是代码:
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))
但是尝试尽可能多的组合,我总是收到错误,比如没有指定数据等。
我的目标是要求用户输入两个日期,这些日期将在日期之间的查询中形成日期从和日期。
非常感谢任何帮助。
谢谢赵