change Datasource of a crystal report at run time
Hi all,
I want to call crystal reports(version 8.5 or 9.0) in my visual basic application. but i dont
want to add Crystal designers to my visual basic application. Instead i would like to create all the reports
using report expert(Using OLEDB method i will open my database and will add a table named customer and give all the
fields to report and in this way this report will show all the data in fields added to report.
it means no filter will be applied)
Then i want to store all of reports at some drive of my hard disk and using crystal viewer control i will
call reports as needed.
now my problem is that i need to change the Datasource of my reports at run time so that it would show the records that
i want to show. my code is like this
Dim ObjApp as new Craxdrt.application
Dim ObjRep as new Craxdrt.report
Dim Con as new ADODB.Connection
Dim Rs as new ADODB.Recordset
Private sub form_Load()
Con.Open "Provider=Microsoft.Jet.Oledb.4.0; Datasource=C:\Data.mdb"
Rs.open "Select * from Customer Where CustName = 'Jhon'",con,AdopenStatic,AdlockOPtimistic
set objrep = objapp.open("C:\customer.rpt")
objrep.Database.SetDatasource Rs
CrViewver1.reportsource = objrep
Crviewver1.ViewReport
End sub
Now this code is working fine but it is showing all the data within fields but according to requirement
of mine it should show only data for customer having name "Jhon". but it is showing data for all the customers
in spite of the fact that i have set the datasource to a recordset that only contains records for customer
named Jhon. but it is not working
if someone has any idea about this situation, kindly help. or suppose if you have any alternative method
kindly guide me to fullfil the requirements
sorry if there is any mistake in my code bcoz i have written this code in notepad...not i visual basic editor
Tayyab
__________________
Tiyyob
|