Solved

Why are there no data displayed in my Crystal Report?

Posted on 2006-11-28
3
240 Views
Last Modified: 2010-04-16
Hi, I'm using VS 2005, .net 2.0 and C#.  I developed my crystal report using the developer version, 11.0 and then add the report to my proejct.  In my project, I have a winform that has a CrystalReportViewer control on it.  I would like to use this form to produce report preview for all the reports in my project.  So, I would like to assign different reprotPath to the CrystalReportViewer control and also different dataset.  

For my first report, I created a dataset in my proejct, dsEventLog.xsd.  I created a table in this dataset in the designer with the columns.  I use the following code to run my report but the crystal report displays none of the data that I entered as rows in my code to this dataset's table.  What am I doing wrong here?  Thanks.




        private void btnOK_Click(object sender, EventArgs e)
        {
            dsEventLog dsLog = new dsEventLog();
            String padEventType = null;          
           
            // Associate the instance of 'EventLog' with local System Log.
            EventLog padEventLog = new EventLog("Directory Service", ".");

                padEventType = "Information";

            EventLogEntryCollection padLogEntryCollection = padEventLog.Entries;
            int logCount = padLogEntryCollection.Count;
            string user;
            // Iterate through all 'EventLogEntry' instances in 'EventLog'.
            for (int i = logCount - 1; i > 0; i--)
            {
                System.Diagnostics.EventLogEntry padLogEntry = padLogEntryCollection[i];
                // Select the entry having desired EventType.
                if (padLogEntry.EntryType.ToString().Equals(padEventType))
                {
                    DataRow dr = dsLog.Tables[0].NewRow();
                    dr["Date"] = padLogEntry.TimeGenerated.ToShortDateString();
                    dr["Time"] = padLogEntry.TimeGenerated.ToShortTimeString();
                    dr["Source"] = padLogEntry.Source.ToString();
                    dr["Category"] = padLogEntry.Category.ToString();
                    dr["Event"] = padLogEntry.InstanceId.ToString();
                    if (padLogEntry.UserName == null)
                        user = "N/A";
                    else
                        user = padLogEntry.UserName.ToString();
                    dr["User"] = user;
                    dr["Computer"] = padLogEntry.MachineName.ToString();
                    //string[] logItem =
                    //dr.ItemArray = new string[] { padLogEntry.TimeGenerated.ToShortDateString(),
                    //    padLogEntry.TimeGenerated.ToShortTimeString(), padLogEntry.Source.ToString(),
                    //    padLogEntry.Category.ToString(), padLogEntry.InstanceId.ToString(),
                    //    padLogEntry.UserName.ToString(), padLogEntry.MachineName.ToString()}; ;
                    dsLog.Tables[0].Rows.Add(dr);                
                }
            }
            int rows = dsLog.Tables[0].Rows.Count;
            ReportPreview logPreview = new ReportPreview();
            string reportPath = Application.StartupPath + "\\" + "EventLogReport.rpt";
            logPreview.crViewer.ReportSource= reportPath;

            logPreview.crViewer.Refresh();
            logPreview.crViewer.RefreshReport();

            if (ckbPreview.Checked == true)
            {
                logPreview.ShowDialog();
            }
            else
            {
                logPreview.crViewer.PrintReport();
            }
            //myDoc.Dispose();
            logPreview.Dispose();

            //All done, clean up
            dsLog.Tables.Clear();
            dsLog.Dispose();
            GC.Collect();
            Cursor = Cursors.Default;

        }
0
Comment
Question by:lapucca
  • 2
3 Comments
 
LVL 5

Accepted Solution

by:
rameedev earned 500 total points
ID: 18034790
I think you should take alook at all your clean up code like logpreview.dispose(),dslog.tables.clear(),dslog.dispose can you try without these...

and one more question how are you assigning the datasource to .rpt file.
0
 

Author Comment

by:lapucca
ID: 18038817
When I created the crystal report I selected the dsEventLog.xsd that I created in my C# proejct.  All the data field in my CR are from this dataset's table.  I don't thknk             dsLog.Tables.Clear();
            dsLog.Dispose();
would be the problem but I tried it as you suggested and it doesn't make any difference as I thought.  
 
Thanks.
0
 

Author Comment

by:lapucca
ID: 18039193
Ok, I got it solved.  I added reportdocument and it worked.  Thanks.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video discusses moving either the default database or any database to a new volume.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

760 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

21 Experts available now in Live!

Get 1:1 Help Now