?
Solved

Crystal Report with dynamic query inside VB.NET

Posted on 2006-07-17
5
Medium Priority
?
663 Views
Last Modified: 2012-08-13
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
0
Comment
Question by:Kudzullc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 3

Author Comment

by:Kudzullc
ID: 17122697
cont.  

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

Lucas
0
 
LVL 1

Accepted Solution

by:
mordizer earned 2000 total points
ID: 17122883
Hi Kudzullc, I'm not really an expert around here but I've just solved a similar problem and it might get you going while you wait for someone cleverer to chip in :)

Basically I did this to solve my problem :

1)  I made a typed dataset to hold the data I wanted to report on and used that to build the visual report in the normal designer.

2)  I made a new class and inherited from the report I designed in step one and made a private instance of a typed dataset of the same type as I built the report off.

3)  In the constructer of this new class I passed in the dynamic parts of the query I wanted to run and then filled the dataset within the class.

4)  I called the me.setdatasource(dsExample) to bind my new report class to the dataset I'd built.

For example if you create a dataset called dsCatalogue and drag the tables onto it to show a product catalogue you could use that to develop a report called ShowCatalogueReport.  Once you're happy with that report save it and create a new class - call it BindDataToReport or something and it would look like this.

Public class BindDataToReport
    Inherits ShowCatalogueReport

    Private mdsCatalogue as new CatalogueDataset

    Public Sub New(byval strProductHeader as string)
         'Some code here to fill mdsCatalogue with data filtered by strProductHeader
         me.setdatasource(mdsCatalogue)
    end sub

End class

You could then use this new class as a report document to show in a viewer.

This has given me a little more control over how I fill up my dataset before it gets bound to the report and if you can figure out my instructions it might keep you going until someone posts the proper way of doing it :)
0
 
LVL 3

Author Comment

by:Kudzullc
ID: 17123928
Thanks for the advice!  I will try it out!

Lucas
0
 
LVL 3

Author Comment

by:Kudzullc
ID: 17125043
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
0
 
LVL 1

Expert Comment

by:mordizer
ID: 17128623
Glad it got you moving again :)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question