Sunday, March 25, 2012

Bind DataSource at runtime and Adding fields [A little help please]

hi,

I am using Crystal Reports 8.5 and Visual Biasic 6.0, the technique that I
was using was I connect the database using the ODBC to the crytal reports and design my report by draging the fields to the reports.

In my new assignment I have to bind a ADODB recordset to the report at
run time.

I got 2 Problems.

01. How can I bind a ADODB recordset to the report at run time
02. After binding the recordset how can I add the fileds to the report
content area

A small help on this please.

Thank you.Dim conn As ADODB.Connection 'CONNECTION TO BROKER QUERIES
Dim rs As ADODB.Recordset 'HOLDS ALL DATA RETURNED FROM QUERY
Dim crystal As CRAXDRT.Application 'LOADS REPORT FROM FILE
Dim Report As CRAXDRT.Report 'HOLDS REPORT

Set conn = New ADODB.Connection
conn.Open "Provider=MSDAORA.1;User ID=scott;Data Source=qb;Persist Security Info=False", "sebsv4", "sebsv4pwd" 'THESE OPTION VALUES ARE BEST FOR VB

Set rs = New ADODB.Recordset
rs.Open q, conn, adOpenStatic, adLockReadOnly

Set crystal = New CRAXDRT.Application 'MANAGES REPORTS

Set Report = crystal.OpenReport(App.Path & "\report1.rpt") 'OPEN OUR REPORT

Report.DiscardSavedData 'CLEARS REPORT SO WE WORK FROM RECORDSET
Report.Database.SetDataSource rs 'LINK REPORT TO RECORDSET

CRViewer1.ReportSource = Report 'LINK VIEWER TO REPORT
CRViewer1.ViewReport 'SHOW REPORT|||thanks for the quick reply sraheem

another small problem,

if I am using the report designer in VB like that, when I have draged a field name in to the report
it shows the field name as

field:<TableName>.<ColumnName>

now If I am doing the data binding at run time how can I add the recordset columns in to the report, since there is no data property on report fileds

Thanx.|||just capture report sections like below and add fields...

Dim crxdetail As CRAXDDRT.Section 'Section Decleration
Dim crxPageHeader As CRAXDDRT.Section 'Section Decleration
Dim crxPageFooter As CRAXDDRT.Section 'Section Decleration

Set crxdetail = Report.Sections.Item("D") 'Detail Section
Set crxPageHeader = Report.Sections.Item("PH") 'Detail Section
Set crxPageFooter = Report.Sections.Item("PF") 'Detail Section

crxdetail.AddFieldObject "{e." & rs(i).Name & "}", 1000, 0

where e is the report command object name or table name in your case.

No comments:

Post a Comment