2016-03-28 53 views
0

我想要在VB.NET中使用MS Access中的select查詢年份之間的數據。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

什麼是您所遇到的問題? – MusicLovingIndianGirl

+0

我想要在報告中使用select查詢在vb,net –

+0

年明智的數據你能告訴我們你得到什麼嗎?錯誤消息? – Alireza

回答

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())"