Can't get the Crystal Reports Viewer to bind with my dataset.

B

Bob Clegg

I am in the same boat as Moondog on the 2nd July.
I have a report designed against a dataset.
Proved the datasset is OK by dropping a datagrid onto the form and it binds
OK to the data.
But the report is empty (except for headers). My method is similar to
Moondog except the dataset is based on a SProc.
The dataset is instantiated in FormA, passed to a DataHandling class which
fills it. by executing the SProc
it is then passed to the report form in the constructor.
The constructor then passes it down to a subroutine 'loadreport' which
attempts to bind it to the report viewer
Code is :
Private Sub loadreport(ByRef dsevents As dsReportEvent)

' Called by new(ByRef dsevents As dsReportEvent)

Me.dg1.DataSource = dsevents

Me.dg1.DataMember = "Table"'Datagrid sanity check

mRpt = New rptEventReport 'report class underlying report based on dsEvents

mRpt.SetDataSource(dsevents)

Me.crvMain.ReportSource = mRpt 'setting the viewer

End Sub

Any help would be appreciated.
Thanks
Bob
 
B

Bob Clegg

Hi Brian,
Thanks for your reply.
No Joy.
I coded:
Private Sub loadreport(ByRef dsevents As dsReportEvent)

Dim crReportDocument As rptEventReport

crReportDocument = New rptEventReport

Dim ds As DataSet

ds = dsevents 'NOTE here I am still pointing to my original dataset.

Dim dstest As String = ds.GetXml 'dstest shows well formed doc with data



crReportDocument.SetDataSource(ds)




Me.crvMain.ReportSource = crReportDocument

Me.crvMain.Visible = True

End Sub

The test string showed an xml doc with data.

I do have dates in the data.
I'll alter the sproc / dataset / report to give a one integer field rowset
and see if that helps.
If it does then I'll build up from there.
If it is data then this control is not much use.
Is there any 3rd party viewer around that anybody knows of?
Thanks
Bob

BrianDH said:
Try this.
Dim crReportDocument As rptEventReport
crReportDocument = New rptEventReport
Dim dsevents As DataSet = "get your dataset values"
Dim strTests As String = dsevents.GetXml ' break point here view/test your DS XML
crReportDocument.SetDataSource(dsevents)
CrystalReportViewer1.ReportSource = crReportDocument
CrystalReportViewer1.Visible = True

If this does not work.
Question: Are you using any formulas? running totals? also date time
fields can give you fits with CR.
 
B

bclegg

OK Problem Solved.
You have to use the overloaded version of the dataadapter fill command.
ie.
Dim cmdConn As New SqlClient.SqlCommand("proc_GetEventReportData",
NewSqlClient.SqlConnection(strConnection))

cmdConn.Parameters.Add(New SqlClient.SqlParameter("@strIDList",
SqlDbType.NVarChar))

cmdConn.Parameters("@strIDList").Value = mstrUnitList
cmdConn.CommandType = CommandType.StoredProcedure
Dim da As New SqlClient.SqlDataAdapter(cmdConn)
Dim ds As New dsReportEvent
da.Fill(ds, "ReportEvent")
Dim rd As New rptEventReport
rd.SetDataSource(ds)

The big 'break through' was realising that "ReportEvent" was needed.
The documentation alludes to this but leaves the impression that is it
mainly for table verification.
This HAD to be the name of the Element that was inside my typed dateset.
My element was handrolled and not actually a table so it seemed
reasonable to use the default constructor and accept the generated table
name "Table".
Alas no.
Moondog, if your out there, good luck.
regards
Bob
 
M

Moondog

Hmmm, I think I did try that method bclegg, but still had no luck.

But I did manage to get it working. Here's how:

In my code after I get my dataset I run this line once:

myDataSet.WriteXmlSchema("C:\MyReport.xsd")

This creates a file called MyReport.xsd that contains the description
of my data. Next I create a new Crystal Report using MyReport.xsd as
my ADO.NET (XML) source. Once the new report is created you can
delete MyReport.xsd, and also delete the line of code that created the
xsd file. The new report created will then accept my dataset during
runtime.

Dominic Isaia (Moondog)
(e-mail address removed)
 
Top