Solved

Crystal Report with dynamic query inside VB.NET

Posted on 2006-07-17
5
655 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
  • 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 500 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now