我希望在VB.NET中的MS Access中使用select查询的年份之间的数据。
我的代码是:
Try
Cursor = Cursors.WaitCursor
Dim rpt As New rptLedger()
Dim myConnection As OleDbConnection
Dim MyCommand As New OleDbCommand()
Dim myDA As New OleDbDataAdapter()
Dim myDS As New DataSet 'The DataSet you created.
myConnection = New OleDbConnection(cnString)
MyCommand.Connection = myConnection
MyCommand.CommandText = "SELECT Ledger.rdate, Ledger.pDate, Ledger.receipttotal, Ledger.PaymentTotal, Ledger.PartyName, Ledger.CompCode, Ledger.Cmpcode, Ledger.rnarration, Ledger.pnarration FROM Ledger where pDate >= dateadd(year,-1,GETD())"
MsgBox(MyCommand.CommandText)
MyCommand.CommandType = CommandType.Text
myDA.SelectCommand = MyCommand
myDA.Fill(myDS, "Ledger")
CrystalReportViewer1.ReportSource = rpt
myConnection.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
答案 0 :(得分:1)
您需要访问功能和语法:
MyCommand.CommandText = "SELECT Ledger.rdate, Ledger.pDate, Ledger.receipttotal, Ledger.PaymentTotal, Ledger.PartyName, Ledger.CompCode, Ledger.Cmpcode, Ledger.rnarration, Ledger.pnarration FROM Ledger where pDate >= DateAdd('yyyy', -1, Date())"