push data into crystal report

G

Guest

Hi,

I want to push data from a winform into a crystal report document but .
I found everithing in the FAQ 'crystal report' and other posts in forums but it doesn't work.
Here is my code.(it doesn't work).

***************
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim crpt As New CrystalReport2
Dim strSQL As String = "SELECT * from products WHERE SupplierId = 1"
Dim ds As New DataSet
Dim conn As SqlConnection = New SqlConnection("server=turing;database=northwind;integrated security=true;")
Dim da As SqlDataAdapter = New SqlDataAdapter(strSQL, conn)

conn.Open()
da.Fill(ds, "products")
conn.Close()

crpt.SetDataSource(ds)
CrystalReportViewer1.ReportSource = crpt

End Sub
***************


If someone could help me.
Thank you.
 
G

Greg Young

#region GetCrystalPushReport
private ReportDocument GetCrystalPushReport(ReportDescriptor _Descriptor)
{
if(_Descriptor.Describes == null) {
throw new System.ArgumentNullException("Descriptor.Describes") ;
}
Report Report = _Descriptor.Describes ;
ReportDocument Return = new ReportDocument() ;
DbDataProvider data = new DbDataProvider() ;
string filename = data.GetReportFile(Report) ;
Return.Load(filename) ;

//got the report
DataSet bar =
CrystalDataBuilder.GetInstance().GetReportData(_Descriptor);
SetReportDataSource(Return, bar);
return Return;
}


is what I use ... the Descriptor has metadata information associated with it
that describes the data to pull ...

private void SetReportDataSource(ReportDocument _Report, DataSet _ds) {
_Report.SetDataSource(_ds) ;

for (int i = 0; i < _Report.ReportDefinition.ReportObjects.Count; i++) {
ReportObject CurrentObject = _Report.ReportDefinition.ReportObjects;

if(CurrentObject.Kind ==
CrystalDecisions.Shared.ReportObjectKind.SubreportObject) {
ReportDocument SubReport =
_Report.OpenSubreport(((SubreportObject)CurrentObject).SubreportName);
SetReportDataSource(SubReport, _ds) ;
}
}
}

sets the data source for the report and all subreports ...
laumon said:
Hi,

I want to push data from a winform into a crystal report document but .
I found everithing in the FAQ 'crystal report' and other posts in forums but it doesn't work.
Here is my code.(it doesn't work).

***************
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim crpt As New CrystalReport2
Dim strSQL As String = "SELECT * from products WHERE SupplierId = 1"
Dim ds As New DataSet
Dim conn As SqlConnection = New
SqlConnection("server=turing;database=northwind;integrated security=true;")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top