Unanswered: Changing crystal report datasource at runtime
Hi all, i am developing a software which using 2 databases. so i want to change the database of report at runtime. i am using crystal report activex designer runtime and design time library. i want to change the
'set the database to use for this report
For Each objDatabaseTable In Me.Database.Tables
objDatabaseTable.Location = App.Path & "\GramCommon.mdb"
objDatabaseTable.SetSessionInfo "Admin", Chr(10) & "PASSWORD"
Dim sql As String
sql = "sElect * from Certificate"
Set adoRs = CreateObject("adodb.recordset")
adoRs.Open sql, "Provider=Microsoft.Jet.OLEDB.4.0;Password=''; Data Source=" & App.Path & "\gramcommon.mdb;Persist Security Info=false", adOpenKeyset, adLockBatchOptimistic
Me.Database.AddADOCommand adoRs.ActiveConnection, adoRs.ActiveCommand
i m using this sort of coding, i tried lot, it gives no error but it gives data of the database which was used while design time of report.
pl. help to get database changed at runtime, if anybody knows.
The following code will code very will in the standalone crystalreport. but it failed in RDC environment. I don't know which type you develop.
Dim CrxApp As New CRAXDRT.Application
Dim CrxRpt As CRAXDRT.Report
Private Sub Form_Load()
Set CrxRpt = CrxApp.OpenReport(App.Path & "\Data\report1.rpt")
CrxRpt.Database.Tables(1).SetLogOnInfo sName, dbname, "", ""
'Sets the location for the first table in the report to the Access database. If the report has
'more than one table the same location will propagate through all of the tables.
'You can set a new location for each table individually based on it's index in the Tables collection.
CrxRpt.Database.Tables(1).Location = "Your Table Name"
CRViewer1.ReportSource = CrxRpt