Using Crystal Reports

whizkid123

Active member
Joined
Dec 11, 2002
Messages
33
Location
India
Hi! Im working on VB.Net and this is the first time that Im using crystal
reports. Im not able to find any basic documentation regarding how do we go
about it. I have created & designed a report. Im using MS Access and by
connecting to it have got the list of tables in the database fields
explorer. Now after that, Ive added a CRV on my form and set the datasource
to a dataset that Ive created programatically. When I view the report, it
does not even load the design elements in my report. Its fully blank. The
dataset is not blank. Can anybody please help me with this. If there are any
tutorials, sample codes on this and if somebody could point me to it, it
would be really helpful. Thanx!
 
Ive got Enterprise Architect edition and it came with an example for both WinForm and WebForms. Check here or the equivelent location on your box:
C:\Program Files\Microsoft Visual Studio .NET\Crystal Reports\Samples\Code\WinForms\VB
 
sorry for digging up an old thread.

whizkid123, im facing the same situation as you. have you managed to solve the problem?

ive looked at the example but its a tad simple..

-ashrobo
 
after you have created your dataset pass it to the form that will display your report and set the forms private dataset variable to the dataset being passed to the form

Code:
Private m_dsReportSource As System.Data.DataSet


   
Public Sub New(ByVal dsReportSource As System.Data.DataSet)
        MyBase.New()


        This call is required by the Windows Form Designer.
        InitializeComponent()


        Add any initialization after the InitializeComponent() call


          set the forms dataset variable to passed dataset


        m_dsReportSource = dsReportSource


    End Sub

then setup your report as follows....

Code:
Private Sub CrystalReportViewer1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles CrystalReportViewer1.Load

         myReport = New repWhatEver()


         myReport.SetDataSource(m_dsReportSource)


         Me.CrystalReportViewer1.ReportSource = myReport


End Sub
 
Maybe not the most elegant way but I create a temp dataadapter and dataset on the form in design mode to make all the required fields accessible. Then when the report is as I want it I just assign the dynamic dataset to the report at runtime and all works a treat
 
i tried it but it didnt work as i thought it would.. when the crystal report viewer was loaded, it loads the crystal report which in turn asked me about the logon details. any clues?

-ashrobo
 
This example will show you how you can dynamicaly load data in to a report and view in a CRV

Code:
Imports CrystalDecisions.CrystalReports
Imports System.Data
Imports System.Data.SqlClient
Public Class frmDeliveryReport
    Inherits System.Windows.Forms.Form
    Public myRpt As New rptOrderDelivery()
    Public intDeliveryId As Integer

<HERE FORM DESIGNER CODE>

    Private Sub frmDeliveryReport_Load() Handles MyBase.Load
        Dim myAdapter As SqlDataAdapter = New SqlDataAdapter("SELECT Some Day Where OrderDelivery.DeliveryID = " & intDeliveryId, mySQL)
        Dim myDS As DataSet = New DataSet()
        myAdapter.Fill(myDS)
        myRpt.SetDataSource(myDS.Tables(0))
        crvDEL.ReportSource = myRpt
        crvDEL.Zoom(2)
    End Sub


Remeber these Steps

1- Design a Crystal Report from ADO.NET generated XML file. you can create it from adding a new XML Schema File or asking and Adapter to generate a data set. this file is nothing just a sequence of colums which your Query will return.

2- Then on the Report Form you first need to instentiate that report file ang generate some data set from some query

3- then From that generated data set , set the datasource property of Report to that data set. so the report loads data in it

4- and at the end you need to set to CRV report source property to that generated report.
 
Last edited by a moderator:
Madz, havent tried your approach, but just looking at the steps required it seems to be a lot of effort whereby simply having a temp dataset & dataadapter in design mode would suffice.
 
a million thanks to you, madz.. :) finally, im able to create a report for 1 record. now the problem is the "details" which in my case, is invoice details, cannot be displayed. i dragged the field "itemno" down onto the report and when i run it, i get "query engine error".

- ashrobo
 
Originally posted by hog
Madz, havent tried your approach, but just looking at the steps required it seems to be a lot of effort whereby simply having a temp dataset & dataadapter in design mode would suffice.

in fact, i only managed to get it going after following Madzs steps..

hog, i thought Madzs steps were similar to yours. he has a XML schema file while you have a dataset and dataadapter.

thanks guys/gals,
- ashrobo
 
Dear There is nothing difficult with it. Just Do these Steps

1- Generate an XML file this is required for Crytal Report if you want to use ADO.NET with Report. its much easier to generate it Just you need to add an XML Schema File to your Solution. then from Server Explorer Expand the SQL Server List and then Drag the Desired Table to the File.

2- Then FRom CR Report Designer choose ADO.NET it will ask you to open some XML File then path to that file and choose the columns which you want to show on table.

3- then design the Report with code above. and Query the Table which you want to show on report. and fill the report with that.

the above example it from a real project this shows the Delivery Report on a paid order. Which shows the desired delivery report and get it by report id.

Here an other example which shows the sales record on report
it is much easier. and same as the old one

Code:
    Public rptDel As New rptPaymentsReport()
    Private Sub frmDealerReport_Load() Handles MyBase.Load
        On Error Resume Next
        Dim myAdapter As SqlDataAdapter = New SqlDataAdapter(strQuery, mySQL)
        Dim myDs As DataSet = New DataSet()
        myAdapter.Fill(myDs)
        rptDel.SetDataSource(myDs.Tables(0))
        crvDealer.ReportSource = rptDel
        crvDealer.Zoom(2)
        crvDealer.RefreshReport()
    End Sub
 
urmm, i am able to display the invoice headers based on the steps that youve listed out, Madz..

its the Invoice Details that are not coming out now.. fields such as "Invoice.InvoiceNo", "Invoice.InvoiceDate", etc are fine. however, if i add the field "InvOrders.ItemNo", the error will occur but if i add the field "InvOrders.InvoiceNo", no error.

:confused:
-ashrobo
 
I suppose its each to his own. Ive done loads of reports using my method with no problem. Just seems like there is more steps in your method. Anyway whichever way its done they both work so thats all that matters :-)
 
OK madz, Im always up for trying something new....

I have added a blank xml file to my project, but if I try to drag a table from my access connection it does not allow me to do so.
 
Originally posted by hog
OK madz, Im always up for trying something new....

I have added a blank xml file to my project, but if I try to drag a table from my access connection it does not allow me to do so.
really? i could just drag the table over without any errors..
 
I dont thing so, there might be some thing missing coz it is so much easy just drag the table to designer and it will add a table.
 
No...it wont have it?

I add a blank xml file to my solution
I expand the tables in solution explorer
I click and drag the required table, but get the black circle with the line through it signifying not allowed, which doesnt let me do jack with the table??
 
And its a result......

Thx ashrobo, now to have a play around....
 
Back
Top