crystal report refers to wrong .mdb

mmy

Member
Joined
Oct 5, 2007
Messages
24
Programming Experience
1-3
In VB.NET 2005 I'v added a crystal report (project - add windows form - crystal report - "rapport.rpt")

With the report wizard I created a new connection (create new connection - OleDb (ADO) - Microsoft Jet 4.0 ... - data base name: test.mdb)

I selected the table, and placed the fields on the report. In preview, everything is normal.

On frmMain I'v placed the CrystalReportViewer control to watch this report. First I make a DataSet and DataTable (with the content from test.mdb). I can view this content in a DataGridViewer.

VB.NET:
Public Class frmMain

        Dim strConnection As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=test.mdb;"
       Dim objConnection As OleDbConnection = New OleDbConnection(strConnection)
       Dim objDataSet As DataSet
       Dim objDataAdapter As OleDbDataAdapter

Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        objConnection.Open()
        objDataSet = New DataSet("TEST")
        objDataAdapter = New OleDbDataAdapter("select * from tblKlanten", objConnection)
        objDataAdapter.Fill(objDataSet, "Klanten")
        objConnection.Close()
        DataGridView1.DataSource = objDataSet.Tables("Klanten")
End Sub

Private Sub btnRapport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRapport.Click
        Dim objReport As New rapport
        objReport.SetDataSource(objDataSet)
        CRviewer.ReportSource = objReport
End Sub
End Class

If I open the report now, everything is ok. But it still gets the content directly from test.mdb (like I said in the wizard), but it should get its content from the DataSet.

If I rename test.mdb to testX.mdb and alter the following:
Dim strConnection as String = "Provider=Microsoft.......;Data Source=testX.mdb;" --> the DataGridView still works ok, but still the report wants to load test.mdb instead of the DataSet (and the DataSet works with testX.mdb).

Does anybody know how to solve this? Not working with the wizard...ok, but how can I design the report then? Current Connections in the wizard is empty, so I have to choose create new connection...

EDIT: it seems this test does work (even if I change the name of the .mdb). Seems in my original project I have problems because I use subreports. I don't use .SetDataSource for my subreport, so I think this is the problem....(if I find out what's the problem, I'll post it)

EDIT 2: no success : ( I declare 2 report objects, and use SetDataSource for both but still no luck....
 
Last edited:
Back
Top