Solved

Crystal Report with dynamic query inside VB.NET

Posted on 2006-07-17
5
660 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 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
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…

690 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