Ok, I tried the following:
I added a new form to my project.
On that form I placed a CrystalReportViewer.
Then I created a report using the new report wizzard.
I made a connection using the 'create new connection'.
When I open the report it works and I get the data I want to see.
But here is my problem:
Now I select another database.
But my report shows the data of the database I set the connection in my crystal report to.
I used the following code:
VB Code:
Imports System.Data Imports System.Data.OleDb Public Class Report Dim myConnection As New OleDb.OleDbConnection Private Sub Report_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load myConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDatabasePath myConnection.Open() Dim CrystalReportViewer1 As CrystalDecisions.Windows.Forms.CrystalReportViewer = New CrystalDecisions.Windows.Forms.CrystalReportViewer Dim Report As CrystalDecisions.CrystalReports.Engine.ReportDocument = New CrystalDecisions.CrystalReports.Engine.ReportDocument CrystalReportViewer1.ActiveViewIndex = 0 CrystalReportViewer1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle CrystalReportViewer1.DisplayGroupTree = False CrystalReportViewer1.Dock = System.Windows.Forms.DockStyle.Fill CrystalReportViewer1.Location = New System.Drawing.Point(0, 0) CrystalReportViewer1.Name = "CrystalReportViewer1" Dim QueryString As String = "select * from tblLand" 'Your Query here 'Dim Connection As New OleDbConnection(funcs.con) 'Your Database Connection Here 'Connection.Open() Dim Adapter As OleDbDataAdapter = New OleDbDataAdapter(QueryString, myConnection) 'Passing the query in the connection Dim DataSet As DataSet = New DataSet() 'DataSet Adapter.Fill(DataSet) Dim DataTable As DataTable = New DataTable 'DataTable DataTable = DataSet.Tables(0) 'filling the datatable here Report.Load(Application.StartupPath & "/CrystalReport1.rpt") 'Report Name Here Report.SetDataSource(DataTable) CrystalReportViewer1.ReportSource = Report End Sub End Class




Reply With Quote