Public Sub PerdiemReport() ReportPath = Application.StartupPath & "\Reports\CrystalReport1.rpt" conn = New OleDb.OleDbConnection(sconnString) Dim pdadt As DataTable = New DataTable() cmd.CommandText = "SELECT * FROM [per_diem_accomodation] WHERE [project number]='PR-01' AND " & _ "MONTH([current month])= 4 AND YEAR([current month])=2014" cmd.Connection = conn adp.SelectCommand = cmd 'pdadt.Rows.Clear() adp.Fill(pdadt) 'DataGridView1.DataSource = pdadt Dim title As String = "Project Payroll-Per diem Report" Preview(ReportPath, pdadt) 'pdadt.Dispose() 'pdadt = Nothing 'adp.Dispose() 'adp = Nothing End Sub Public Sub Preview(ByVal ReportPath As String, ByVal ds As DataTable) Dim rep As New ReportDocument Dim myTableLogonInfo As New TableLogOnInfo Dim myConnectionInfo As New ConnectionInfo 'Dim myTables As Tables Dim myTable As Table rep.Load(ReportPath) rep.SetDataSource(ds) ' myTables = rep.Database.Tables With myConnectionInfo .ServerName = Application.StartupPath & "\projectpayrolls.accdb" .DatabaseName = "" .UserID = "" .Password = "" End With For Each myTable In rep.Database.Tables myTableLogonInfo = myTable.LogOnInfo myTableLogonInfo.ConnectionInfo = myConnectionInfo myTable.ApplyLogOnInfo(myTableLogonInfo) Next CrystalReportViewer1.ReportSource = rep End Sub
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)