Reputation: 1
I want data between years using select query in MS Access in VB.NET.
My code is:
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
Upvotes: 0
Views: 39
Reputation: 56026
You need Access functions and syntax:
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())"
Upvotes: 1