Print Page | Close Window

Report is generated but shows no data

Printed From: Crystal Reports Book
Category: Crystal Reports for Visual Studio 2005 and Newer
Forum Name: Data Connectivity
Forum Discription: How to connect to data sources and export reports
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=301
Printed Date: 28 Apr 2024 at 1:30pm


Topic: Report is generated but shows no data
Posted By: a9192shark
Subject: Report is generated but shows no data
Date Posted: 09 Mar 2007 at 6:31am
Hello,
 
I have developed a windows application in VB (VS2005) that is linked to a SQL Server 2005 database.
 
The application will have lots of different reports so I have created a single form called frmPreviewReport that contains a single viewer.
 
When the form loads it updates the ReportSource of the viewer to be a .rpt file and displays the report.  However there is no data in the report.
 
I have added the line Imports System.Data to the top of the forms class file as instructed on an MSDN page.
 
I have verified the database link.
 
I know that there is data and I am only displaying data from a single table.
 
The data is pulled from a dataset defined in the VS project.
 
Do I have to fill the data set?  I thought CR would do that.
 
Why is my report not showing any data?
 
Another issue, that may be linked, is that I keep getting an error message "Unable to find the report in the manifest resources."
 
Hope you can help me!
 
Thanks,
 
Alan.



Replies:
Posted By: hilfy
Date Posted: 09 Mar 2007 at 12:58pm
Yes, you have to fill the dataset.  When working with data sets instead of direct connections to the tables, Crystal expects the data to already be there.
 
As for the error message, is the report included in the project?
 
-Dell


-------------
Proviti, Data & Analytics Practice
http://www.protiviti.com/US-en/data-management-advanced-analytics - www.protiviti.com/US-en/data-management-advanced-analytics


Posted By: rbblack
Date Posted: 26 Apr 2007 at 5:57pm
HI, newbie here.  Could you be more specific as to how to fill the dataset?
 
I would greatly appreciate it!
 
Thanks


Posted By: hilfy
Date Posted: 27 Apr 2007 at 6:25am
Your .NET program has to put data into the dataset prior to running the report that reads the dataset.  How this is done is dependent on how you've set up your dataset.  If it's tables, you can just open the tables.  If it's based on a query, you have to run the query.  If the data is generated through code, then you have to generate the data. (For example, I have an app that does a user audit from Business Objects Enterprise XI.  It gets the user information from BO XI through the SDK and saves it to a table in the dataset.  It then reads user information from our security database and updates the table based on that.  Then it opens up the audit report.)
 
-Dell


-------------
Proviti, Data & Analytics Practice
http://www.protiviti.com/US-en/data-management-advanced-analytics - www.protiviti.com/US-en/data-management-advanced-analytics


Posted By: rbblack
Date Posted: 27 Apr 2007 at 11:34am
Thanks for the reply.
 
OK, so my app is filling the dataset once I choose to save it to database...the report still comes up blank., any other reasons for that?
 
Thanks again


Posted By: hilfy
Date Posted: 30 Apr 2007 at 4:06pm
...once I choose to save it to database...
 
Ok, I'm confused....
 
Does the report read from an in-memory dataset or from the table in the database?  If it's from an in-memory dataset, then saving it to the database makes no sense in this situation.  If you want it to read from the database, then it needs to connect directly to the database, not to a dataset in your application.
 
-Dell


-------------
Proviti, Data & Analytics Practice
http://www.protiviti.com/US-en/data-management-advanced-analytics - www.protiviti.com/US-en/data-management-advanced-analytics


Posted By: rbblack
Date Posted: 30 Apr 2007 at 7:27pm
well, actually, in this case I would think that it's one and the same, though I'm probably wrong, because I've set up the report to run from within the application, so you can only access the report while the app is running and while the data is displayed in the app. 
 
Let me start from the beginning... My app (a windows desktop app) calls a web service to get the data.  Once it obtains the data the data is displayed in a gridview (on the form that calls the web service, the "search" form) and you can choose which rows to "add to database."  Once the data is added to the database it is displayed on another form with a gridview (the "view" form).  On another form I set up a cr-viewer to connect to the same dataset that the view form is displaying data from.  In this case it's only the "title" field, but if I get this working then in the future there'll be more fields added.
 
I'm probably going about this all wrong, but this is the first report I've ever tried to do and I didn't do any studying beforehand...
 
If it's not a waste of your time to help an amatuer I'd like to hear how you would go about this...
 
Is it possbible to have the report in the same app that fills the dataset, or do I have to create a report app separately?
 
Thanks again!


Posted By: hilfy
Date Posted: 01 May 2007 at 7:08am
You can absolutely have your report in the same app that fills the dataset - that's the way it's supposed to work when you are running off of in-memory datasets. 
 
What does your code do to the dataset after it saves the data to the database?
 
How are you setting the datasource for the report?
 
-Dell
 


-------------
Proviti, Data & Analytics Practice
http://www.protiviti.com/US-en/data-management-advanced-analytics - www.protiviti.com/US-en/data-management-advanced-analytics


Posted By: rbblack
Date Posted: 02 May 2007 at 3:10pm

After an item is added to the database:

'''All titles in the database are loaded into the in-memory datatable;

''' The (viewer) control monitors for changes to the datatable and auto saves changes made to each field.

I used the Smart Tasks panel to select the datasource/dataset from "Current connections"
I also used the code-based development model in the Crystal Reports for Visual Studio 2005 tutorial with the same results.  I get a beautifully generated report with the "Titles" header and the rest is blank.
 
Thanks again-Rob


Posted By: jabi
Date Posted: 08 May 2007 at 1:21pm
Hello:

I exactly have the same trouble, i try show a report but it appears without data, only column's titles appear. I don't know what option i've to choose for a database in Sql Server:


Option i am choosing is ADO.NET and then i select my dataset, but it doesn't work.

I use Visual Studio 2005 and Sql Server 2005 too.

Thanks,

Javi, from Spain.


Posted By: hilfy
Date Posted: 08 May 2007 at 1:43pm

I'm using the Report Document object model instead of the Viewer object mode.  My WinForms application has two forms.  One is the main form where the user selects some parameters which then are used to get the data that is saved to the ADO.NET dataset.  The other has the report viewer component and is used to display the report. 

The Creator on the viewer form has been overridden so that the DataSet can be sent to it.  So, the creator looks like this:

private BOEUserAuditRpt auditRpt;

public BOEAuditRptViewer(DataSet dsAuditInfo)
{
  InitializeComponent();
 
auditRpt = new BOEUserAuditRpt();
  auditRpt.SetDataSource(dsAuditInfo);
  auditRptViewer.ReportSource = auditRpt;
}
 
This explicitly sets the datasource of the report object AND the report souce of the viewer object.
 
The code that shows the form looks like this:

private void RunReport()
{
 
BOEAuditRptViewer viewer = new BOEAuditRptViewer(dsAuditInfo);
  viewer.Show();
}
 
-Dell


-------------
Proviti, Data & Analytics Practice
http://www.protiviti.com/US-en/data-management-advanced-analytics - www.protiviti.com/US-en/data-management-advanced-analytics


Posted By: rbblack
Date Posted: 08 May 2007 at 7:51pm
Would you happen to have that in VB code?


Posted By: hilfy
Date Posted: 09 May 2007 at 6:37am
No, sorry!  I only work in C# right now and I've never done anything in VB.
 
-Dell


-------------
Proviti, Data & Analytics Practice
http://www.protiviti.com/US-en/data-management-advanced-analytics - www.protiviti.com/US-en/data-management-advanced-analytics


Posted By: rbblack
Date Posted: 12 May 2007 at 2:03am

That's cool, I found a C#-VB converter here: http://authors.aspalliance.com/aldotnet/examples/translate.aspx - http://authors.aspalliance.com/aldotnet/examples/translate.aspx  in case anybody else has this problem...I'm going to learn C# anyway since all of the .net code samples for the Amazon Web Service are in C#.

For this project I went ahead and used VS2005's Report Viewer which works like a charm, it just doesn't have as many export options as CR. 
 
I'm just disappointed that the CR Viewer didn't work with the reduced code in VB.  I'm wondering if it's a VB bug or a CR bug or my code (though I followed every step in the tutorials to a tee). 
 
When I get time I'll do this same project in C# and see what happens.  Thanks for all your help Dell.


Posted By: Mike W
Date Posted: 28 May 2007 at 9:17am
Hi,
 
I'm suffering from the same problem. . . 
 
I've been unsuccessfully trying to get a report working in a Windows Forms app that I am working on in VS2005/VB.NET.
 
In the end, I decided to try getting it to work using the tutorial data (VB_Win_Data_DataSets).  This worked fine with the xtreme.mdb.  I then created a new dataset schema pointing it at a simple Stored Procedure "SELECT * FROM tblCustomer" in the production SQL Server database.  The data previewed ok.  I then created a new report which simply displayed the data, without any sorting, grouping or filtering.  Finally, I substituted the code in the CustomerDataSet property in the DataSetConfiguration class. 
 
The "myDataSet" dataset is populated (I can iterate thru it and display the data) prior to the customerReport.SetDataSource call.  As with other folks, the report headers are displayed but no data and only a single page. . .
 
Has anyone got any bright ideas please?
 
Best regards
 
Mike W
 
 


Posted By: hilfy
Date Posted: 28 May 2007 at 11:42am
What code are you using to set the DataSource of the report and the ReportSource of the viewer?
 
-Dell


-------------
Proviti, Data & Analytics Practice
http://www.protiviti.com/US-en/data-management-advanced-analytics - www.protiviti.com/US-en/data-management-advanced-analytics


Posted By: Mike W
Date Posted: 28 May 2007 at 11:43pm
Hi,
 
The code I am using is the standard tutorial sample code in VB_Win_Data_DataSets.
 
Public Class Form1
    Private customerReport As ReportDocument
    Private Sub ConfigureCrystalReports()
        customerReport = New ReportDocument()
        Dim reportPath As String = Application.StartupPath & "\" &  
                                                                                        "Customer.rpt" 
        ' My version of the report displays the CustomerId and name.
        customerReport.Load(reportPath)
        Dim myDataSet As DataSet = DataSetConfiguration.CustomerDataSet
        ' I have placed code to iterate thru myDataSet here and it's
        ' populated with the correct data.
        customerReport.SetDataSource(myDataSet)
        myCrystalReportViewer.ReportSource = customerReport
    End Sub
 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
                                               System.EventArgs) Handles MyBase.Load
        ConfigureCrystalReports()
    End Sub
End Class
The only code changes I have made are to the DataSetConfiguration class.
I use the Enterprise Library, both here and in the app I'm developing to populate the dataset and it works fine.
 
 
Imports System.Data
Imports System.Data.OleDb
Imports Microsoft.Practices.EnterpriseLibrary.Data
Imports Microsoft.Practices.EnterpriseLibrary.Common
Public Class DataSetConfiguration
    Public Shared ReadOnly Property CustomerDataSet() As DataSet
        Get
            Dim dsCustomer As DataSet = Nothing
            Try
                Dim db As Microsoft.Practices.EnterpriseLibrary.Data.Database=
Microsoft.Practices.EnterpriseLibrary.Data.DatabaseFactory.CreateDatabase
                Dim sqlCommand As String = "sel_EBCustomer"
                Dim dbCommand As System.Data.Common.DbCommand = db.GetStoredProcCommand(sqlCommand)
                dsCustomer = db.ExecuteDataSet(dbCommand)
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
            Return dsCustomer
        End Get
    End Property
 
End Class
 
Best regards
 
Mike


Posted By: hilfy
Date Posted: 29 May 2007 at 7:25am
So your original report gets its data from a stored procedure, but what you want to display comes from a local dataset within the application?  That might be part of the problem.... In the report, go to File|Report Options and make sure 'Verify on First Refresh' and 'Verify Stored Procedures on First Refresh' are turned on. 
 
I would also rework the report to run directly from the table instead of from a stored procedure.  There are differences in how Crystal handles data coming from a stored proc vs. data coming from a table.  In your case you're trying to set a table datasource on a report that was designed with a stored proc, which may not work correctly.
 
-Dell


-------------
Proviti, Data & Analytics Practice
http://www.protiviti.com/US-en/data-management-advanced-analytics - www.protiviti.com/US-en/data-management-advanced-analytics


Posted By: Mike W
Date Posted: 29 May 2007 at 9:57am
I've tried using a dataset template based on both the underlying table and a stored proc which is a simple SELECT * from the table.  I assume this is just used for the schema.  The dataset used at runtime just runs the stored proc that I used in the dataset schema.  I've tried setting the 2 parameters are set on and have recreated the report.  I'm still getting the same report with no data. 
 
Best regards
 
Mike


Posted By: BrianBischof
Date Posted: 29 May 2007 at 2:38pm
This is a bit confusing, but I'm thinking that there is a disconnect between the first iteration of the report design and using the MS enterprise library for retrieving the dataset. What I would do is call the code for the MS enterprise library and then immediately save it's schema to an XSD file. Then I would build a report just using that XSD file. That ensures that CR is only reading data using that schema and you can preview it ahead of time to make sure it is getting the right data.

-------------
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>


Posted By: tsikilee
Date Posted: 30 Mar 2008 at 8:02am
It's much easier to work straight with the database. I didn't get the report work either with dataset.


Posted By: mitch
Date Posted: 09 Apr 2008 at 11:03am
Hello Brian,
 
I am reading your book, being a newbie. I have created a report with crystal reports that is packaged with VS2005. I have copied it to a share, and and trying to use setdatasource with a dataset created from a sql stored proceedure. It looks like the reportsource is read properly but the data is form the original report query. I think I undersand what you said about using the .xsd, but if we change our application to a different server wouldn't I have to recreate the .xsd on that server?
 
I have been trying to set the datasource on the untyped report but have very unsuccessful. Is the .xsd the only method to do this? How can the original dataset be overritten?
 
thanks
Mitch


Posted By: BrianBischof
Date Posted: 09 Apr 2008 at 6:05pm
For your first question, you only need the .XSD on the development computer. CR loads the schema into the report file and saves it there permanently. If you change the structure of the dataset file (in ANY way), then you need to create a new XSD and do a Set Datasource Location to force CR to read in the new XSD file.

Re the second question, check the report options and ReportDocument properties to make sure that you aren't saving the data with the report. I've seen other people post similar questions, but this has never happened to me and I don't know the resolution. I make sure I turn off all options to save report data and I use the ReportDocument.SetDataSource() method to load the new dataset into the report (thus overwriting the original dataset)


-------------
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>


Posted By: mitch
Date Posted: 10 Apr 2008 at 10:19am
Thanks for the quick reply. I appreciate your time.
 
I have Discard Saved data when loading reports Checked
 
 
 
After more testing, I found that it was actually passing the dataset, but the Report Selection Criteria from the Designer was still executing.
 
I stripped out the Record Select statement and the Grouping out of the Report Designer and put the report back on the share and then the code to pass the dataset works.
 
Now I have to read up on passing/maniplulating Formula Fields, Parameters and RecordSelection formulas.
Anyone have any tips for these?
 
 
Also in the code below
replaced
crpt.SetDataSource(rptDataSet)
with
crpt.SetDataSource(rptDataSet.Tables("ReportQuery"))
 
shouldn't the first way work?
 
 
 
 

    Private Sub cmdPrintPreview_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdPrintPreview.Click

 

        Dim strReportName As String = " "

        Dim strDisplayedReportName As String = " "

        Dim strReportPath As String = " "

        Dim SelItem As ListView.SelectedListViewItemCollection

 

        Dim strStoredProcName As String = " "

 

 

        Dim crpt As New ReportDocument

 

        ‘frmReportsViewer has CrystalReportsViewer1

        Dim objfrmReportViwer As New frmReportsViewer

 

        Dim rptDataSet As New DataSet()

        Dim rptDataAdapter As New SqlDataAdapter()

        Dim rptcommand As New SqlCommand()

        Dim rptconnect As New SqlConnection()

 

 

        'Check to see if user has selected a displayed report name from the list, then get the actual report name

        Try

            SelItem = Me.lvReportNames.SelectedItems

            If Me.lvReportNames.SelectedItems.Count = 0 Then

                MessageBox.Show("Please select Report and then click Print.")

                Exit Sub

            Else

                strDisplayedReportName = RTrim(SelItem(0).SubItems(0).Text)

            End If

 

            strReportName = RTrim(GetReportName(strDisplayedReportName))

 

        Catch ex As Exception

            MessageBox.Show("Report Selection error. cmdPrintPreview_Click")

            MessageBox.Show(ex.ToString, C_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error)

            Call Close()

        End Try

 

        strStoredProcName = "usp_" & strReportName

 

        Try

 

            rptconnect = New SqlClient.SqlConnection(gstrCNNString)

 

            rptcommand = New SqlClient.SqlCommand(strStoredProcName, rptconnect)

 

            With rptcommand

                .Connection = gcnnSQLConnection

                .CommandType = CommandType.StoredProcedure

                .CommandText = "usp_" & strReportName

            End With

            rptconnect.Open()

            rptDataAdapter.SelectCommand = rptcommand

 

            rptDataAdapter.Fill(rptDataSet, "ReportQuery")

 

            rptconnect.Close()

            ‘Returns the correct number of rows from SQL Server stored proc

            MessageBox.Show(rptDataSet.Tables.Item("ReportQuery").Rows.Count)

 

        Catch ex As Exception

            MessageBox.Show("Data retrieval error. cmdPrintPreview_Click")

            MessageBox.Show(ex.ToString, C_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error)

            Call Close()

        End Try

 

        'Check to see if the data retrieval returned rows.

        Try

 

            If rptDataSet.Tables.Item("ReportQuery").Rows.Count = 0 Then

                MessageBox.Show("No data returned for your report. Check report paramters and expand criteria if applicable.")

                'Me.Close()

                'Me.Dispose()

                Exit Sub

            Else

 

                ' Data found run the report

                strReportPath = c_REPORTNAMEPATH & RTrim(strReportName) & ".rpt"

 

                If Not IO.File.Exists(strReportPath) Then

                    MessageBox.Show("No Path")

                End If

 

                ‘It loads the report from a shared dir correctly

                crpt.Load (strReportPath)

                crpt.Refresh()

                ‘Doesn’t load the dataset into the report.

                crpt.SetDataSource(rptDataSet)

 

                rptDataSet.Dispose()

                rptDataAdapter.Dispose()

 

                With objfrmReportViwer

                    .CrystalReportViewer1.ReportSource = crpt

                    .Refresh()

                    .Show()

                End With



Posted By: sarah7
Date Posted: 25 Mar 2009 at 1:13pm
Hi
I, too, am new to this and am having trouble getting data from a single table into a crystal report.  I have set up a small test database with a few tables and some dummy data.  I've defined a data set as the source for my Visual Studio 2008 project.  The data set appears to be getting filled correctly from my database, as I can right click on a table in the Visual Studio Data Sources window, select Preview Data - and there it is.  But when I define the Data Source Location in the crystal report to be that data set, and preview it - I am picking up some default data from somewhere with days of the weeks, colours of the rainbow (Grey, Green Blue Lime  etc.)  When I execute my application (which does nothing yet except kick off a Crystal Report Viewer) the table appears in Form1 but with no data.  I am stumped, please help.


Posted By: mitch
Date Posted: 25 Mar 2009 at 2:14pm
I ran in this too, pretty common I think.  Try going into Field Explorer -> under Database Fields -> Right click and chose Set Datasource Location. You'll have to drill down to your table or query for your server. Hope this helps.


Posted By: sarah7
Date Posted: 25 Mar 2009 at 3:18pm
Hi Mitch
I checked Database Fields in the Field Explorer, and it is correctly set to point to the appropriate table in my Dataset.  So it must be something else, any more ideas?
Thanks


Posted By: mitch
Date Posted: 25 Mar 2009 at 3:43pm
Hi Sarah7
Sorry, these are under Field Explorer. From Crystal Reports -> Field Explorer. Right click on Database Fields -> Set Datasource Location
 
Connect to your database and table. I had to play with those setting till I was able to set my datasource from there.
Then under Set Datasource Location under properties I manually changed the Provider: SQLOLEDB, Data Source: 'my server name' , Inital Catalog: 'my table name'
I am using SQL Server.


Posted By: sarah7
Date Posted: 25 Mar 2009 at 3:59pm
 
Hi Mitch:
 
I don't have those options.  Under Set Datasource Location...Current Data Source: I only have report, not server.
 
Under report ->sarahDataSet Properties I have:
Database Type: ADO.NET
Internal Connection ID: {some hex stuff}
Class Name: WindowsApplication1.sarahDataSet
 
One other thing, just now I set up a new project, using the same procedure for defining my data source as before.  Instead of Crystal reporting, I created a Microsoft Report, used Microsoft Report Viewer and added it to my Form.  I was able to execute this and see my data in the report. This gives me some confidence that I have set up the database (SQL server) and the dataset correctly, and the dataset is clearly getting populated.  So somehow I am not configuring or connecting Crystal Reports properly to my dataset.


Posted By: mitch
Date Posted: 25 Mar 2009 at 4:18pm
Hi Sarah7,
Excellent getting your report to connect. do you have a connection setting... from solution Explorer -> right click on your project name - > properties -> Settings ... select type = connection -> click on elipses to set the Value....


Posted By: hilfy
Date Posted: 26 Mar 2009 at 10:34am
Sarah,
 
How are you asssigning the dataset to the report?  You need to be sure to set the DataSource of the report to the DataSet in your application prior to viewing the report.  This way it will correctly point to the instance of the DataSet that has data in it.
 
I work with the ReportDocument object model instead of the Crystal Viewer object model.  Here's a sample of what I do in C#:
myRpt = new MyCrystalReport();
rpt.SetDataSource(myDataSet);
viewer.ReportSource = rpt;
 
-Dell


-------------
Proviti, Data & Analytics Practice
http://www.protiviti.com/US-en/data-management-advanced-analytics - www.protiviti.com/US-en/data-management-advanced-analytics


Posted By: sarah7
Date Posted: 27 Mar 2009 at 10:38am
Hi Mitch
 
I have a connection string, it is defined as follows:
 
Data Source=MERLOT\SQLEXPRESS;Initial Catalog=sarah;Integrated Security=True
 
MERLOT is my host, where I am running SQL Server.  'sarah' is the name of my test database.
 
I have been looking into the matter of connection strings and it seems to be an arcane science, not for the uninitiated or fainthearted.
 
I am just wondering, if the Microsoft Reporting is working OK then presumably my connection string is OK, as I'm able to pass the data into my application that way.


Posted By: mitch
Date Posted: 31 Mar 2009 at 4:29pm
Hi Sarah7
 
CR is a learning curve, I agree if you can connect and run MS Reports you are ok. Don't forget to save the CR report, after tweaking changes. Last, I had to manually change in Set Datasource Location ->
Provider: SQLOLEDB
you may want to try the other connection types.
 



Print Page | Close Window