Link to home
Start Free TrialLog in
Avatar of lapucca
lapucca

asked on

No data is displayed in my Crystal Report???

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;

        }
Avatar of Mike McCracken
Mike McCracken

Are you using CR XI Release 2?  It is required for using Crystal XI with VS 2005

http://www.businessobjects.com/products/reporting/crystalreports/compatibility_vs2005.asp

mlmcc
Avatar of lapucca

ASKER

Yes I am using release 2.  Thank you.
Avatar of lapucca

ASKER

I debug through my application and can confirm that there are several rows of data created and inserted in the table, dtLog.  That's what makes this confusing for me.  Thanks.
I don't see where you are associating the new dataset to the report.

mlmcc
Avatar of lapucca

ASKER

In my CR I assign the datasaet  dsEventLog.xsd as the source.  Do I need to something else in the c# code for this?
I don't know since I don't use xsd files.

mlmcc
ASKER CERTIFIED SOLUTION
Avatar of EwaldL
EwaldL

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial