Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Pass ADO Recordset From Fox to a Crystal Report
Message
From
12/07/2002 12:18:41
 
 
To
12/07/2002 01:33:53
General information
Forum:
Visual FoxPro
Category:
Crystal Reports
Miscellaneous
Thread ID:
00677867
Message ID:
00678096
Views:
17
Nancy,

Here's some code from my Essential Fox presentation.
LOCAL oCR AS CRAXDRT.Application
LOCAL oRpt AS CRAXDRT.Report
LOCAL oDB AS CRAXDRT.Database
LOCAL ocDBT AS CRAXDRT.DatabaseTables
LOCAL oDBT AS CRAXDRT.DatabaseTable

LOCAL oConn AS ADODB.Connection
LOCAL oRS AS ADODB.Recordset

* Handle the ADO stuff
oConn = CREATEOBJECT("ADODB.Connection")
oConn.ConnectionString = "Provider=VFPOLEDB.1;Data Source=C:\eFox\Data\tastrade.dbc;Password=''"
oConn.Open()
oRS = CREATEOBJECT("ADODB.RecordSet")
oRS.Open("Select * FROM Customer", oConn)

oCR = CREATEOBJECT("CrystalRuntime.Application")

oRpt = oCR.OpenReport("C:\EFox\ADO1.RPT")

* Create the Database object
oDB = oRpt.Database()

* Get a references to the DatabaseTables collection
ocDBT = oDB.Tables()

* Get a reference to the DatabaseTable object for table 1
oDBT = ocDBT.Item(1)

* Pass the Record Set to Crystal Reports
oDBT.SetDataSource(oRS)

IF oRPt.HasSavedData
	oRPT.DiscardSavedData()
ENDIF

oRpt.PrintOut()
>I've created a CR 8.5 report, using the CR cross-tab expert. I created it using a temporary DBF with the same structure the RS will eventually have.
>
>I've added a CR Viewer to a form, and I'm trying to pass a RS to the report to use instead of the table I used to create the report.
>
>This pseudo code of what I'm doing in Fox:
>
* Declare  vars including:
>LOCAL loConnection AS ADODB.CONNECTION, ;
>loRS AS ADODB.RECORDSET, ;
>loCommand AS ADODB.COMMAND, ;
>loReport AS CrystalRuntime.REPORT, ;
>loApp AS CrystalRuntime.Application
>
>*!* Initialize variables including:
>loApp = CREATEOBJECT('CrystalRuntime.Application')
>loReport = loApp.OpenReport(SalesAnalysisTotal)
>loReport.DiscardSavedData
>
>*!* Create my SQL select based on user choices, detail isn't really important since RS gets created o.k.
>lcCommand = "SELECT blah, blah, etc"
>
>*!* Create the connection
>loConnection = CREATEOBJECT("ADODB.Connection")
>loConnection.Mode = 16 && adModeShareDenyNone
>lcConnection = ;
>	"Provider=VFPOLEDB.1;" + ;
>	"Data Source=" + CURDIR() + "DATA\;" + ;
>	"Mode=Share Deny None;"
>loConnection.OPEN(lcConnection)
>
>*!* Create the recordset
>loRS 	= CREATEOBJECT("ADODB.RecordSet")
>loRS.LockType = 1 && Started with 3
>loRS.CursorLocation = 2 && Started with 3
>loRS.OPEN(lcCommand, loConnection) && Returns several thousand records as expected.
>
>ASSERT loRS.RecordCount > 0 MESSAGE "No records returned!"
>
>loReport.DiscardSavedData() && Altho the report is not saved with data, just for jollies.
>loReport.DATABASE.SetDataSource(loRS,3,1) && Try and exchange the development source with the recordset.
>
>toCrViewer.ReportSource = loReport
>toCrViewer.ViewReport()
>When the report runs, CR reports that no records were selected and that there was error in the database dll. This is no doubt because the temporary table I used to create the report doesn't exist any longer. This tells me Crystal isn't using the RS I passed, but I have no idea why.
>
>TIA.
Craig Berntson
MCSD, Microsoft .Net MVP, Grape City Community Influencer
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform