Link to home
Start Free TrialLog in
Avatar of Kudzullc
Kudzullc

asked on

Crystal Report with dynamic query inside VB.NET

Hi Experts,

I am having trouble with creating a dataset with a dynamic query and using this dataset to populate a Crystal Report.  I have tried two ways.  The frist was to plainly create the dataset and set the datasource and show the form with the report inside.  Nothing happens.  Second try was creating an XML and have the report use the fields as parameters to no avail.  I am stuck and this project is very important to our IT Staff.  I will show some code.

1st Try:
        Dim newView As New rptViewProject
        Dim newfrmReport As New frmReport
        Dim myDataAdapter As New OleDb.OleDbDataAdapter

        myDataAdapter.Fill(myDataSet)

        Dim myDataSet As New DataSet
        myDataAdapter.SelectCommand = New OleDb.OleDbCommand("Select * from items", cnOleDb)
   
        newView.SetDataSource(MyDataSet)
        newfrmReport.CrystalReportViewer1.ReportSource = newView
        newfrmReport.ShowDialog()

returns a blank report.  Is there anything I need to have set in Crystal tht I might be missing?  I know its a vague question but the use of database fields or parameters means different report builds.  I have done the necessary steps to build the report properly ( I think)  I do have other reports for other programs but the all have static information and are not queried.

2nd Try (XML):
        Dim newView As New rptViewProject
        Dim newfrmReport As New frmReport
        Dim myDataAdapter As New OleDb.OleDbDataAdapter

        Dim myDataSet As New DataSet
        myDataAdapter.SelectCommand = New OleDb.OleDbCommand("Select * from items", cnOleDb)

        myDataAdapter.Fill(myDataSet)
   
        Dim result As String = myDataSet.GetXml()
        Dim fileName As String = "c:\temp\Listings.xml"
        Dim sw As IO.StreamWriter = New IO.StreamWriter(fileName)
        sw.Write(result)
        sw.Flush()
        sw.Close()

        newView.SetDataSource("c:\temp\Listings.xml")
        newfrmReport.CrystalReportViewer1.ReportSource = newView
        newfrmReport.ShowDialog()

Nothing here either.  Thanks for your time in advance.  I have looked through EE very thoroughly and got here but I can not seem to locate the information I think I am missing.  

Thanks again!

Lucas
Avatar of Kudzullc
Kudzullc

ASKER

cont.  

I created seperate .rpt files to except parameters in one and database fields in the other.

Lucas
ASKER CERTIFIED SOLUTION
Avatar of mordizer
mordizer

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for the advice!  I will try it out!

Lucas
I used the idea and I have it working.  Instead of Crystal Reports I used PrinterClass and used a template.  Maybe a little more work then I anticipated but it does exactly what I need it to!  Thanks for the help!

Lucas
Glad it got you moving again :)