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.Coun t;
string user;
// Iterate through all 'EventLogEntry' instances in 'EventLog'.
for (int i = logCount - 1; i > 0; i--)
{
System.Diagnostics.EventLo gEntry padLogEntry = padLogEntryCollection[i];
// Select the entry having desired EventType.
if (padLogEntry.EntryType.ToS tring().Eq uals(padEv entType))
{
DataRow dr = dsLog.Tables[0].NewRow();
dr["Date"] = padLogEntry.TimeGenerated. ToShortDat eString();
dr["Time"] = padLogEntry.TimeGenerated. ToShortTim eString();
dr["Source"] = padLogEntry.Source.ToStrin g();
dr["Category"] = padLogEntry.Category.ToStr ing();
dr["Event"] = padLogEntry.InstanceId.ToS tring();
if (padLogEntry.UserName == null)
user = "N/A";
else
user = padLogEntry.UserName.ToStr ing();
dr["User"] = user;
dr["Computer"] = padLogEntry.MachineName.To String();
//string[] logItem =
//dr.ItemArray = new string[] { padLogEntry.TimeGenerated. ToShortDat eString(),
// padLogEntry.TimeGenerated. ToShortTim eString(), padLogEntry.Source.ToStrin g(),
// padLogEntry.Category.ToStr ing(), padLogEntry.InstanceId.ToS tring(),
// padLogEntry.UserName.ToStr ing(), padLogEntry.MachineName.To String()}; ;
dsLog.Tables[0].Rows.Add(d r);
}
}
int rows = dsLog.Tables[0].Rows.Count ;
ReportPreview logPreview = new ReportPreview();
string reportPath = Application.StartupPath + "\\" + "EventLogReport.rpt";
logPreview.crViewer.Report Source= reportPath;
logPreview.crViewer.Refres h();
logPreview.crViewer.Refres hReport();
if (ckbPreview.Checked == true)
{
logPreview.ShowDialog();
}
else
{
logPreview.crViewer.PrintR eport();
}
//myDoc.Dispose();
logPreview.Dispose();
//All done, clean up
dsLog.Tables.Clear();
dsLog.Dispose();
GC.Collect();
Cursor = Cursors.Default;
}
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.Coun
string user;
// Iterate through all 'EventLogEntry' instances in 'EventLog'.
for (int i = logCount - 1; i > 0; i--)
{
System.Diagnostics.EventLo
// Select the entry having desired EventType.
if (padLogEntry.EntryType.ToS
{
DataRow dr = dsLog.Tables[0].NewRow();
dr["Date"] = padLogEntry.TimeGenerated.
dr["Time"] = padLogEntry.TimeGenerated.
dr["Source"] = padLogEntry.Source.ToStrin
dr["Category"] = padLogEntry.Category.ToStr
dr["Event"] = padLogEntry.InstanceId.ToS
if (padLogEntry.UserName == null)
user = "N/A";
else
user = padLogEntry.UserName.ToStr
dr["User"] = user;
dr["Computer"] = padLogEntry.MachineName.To
//string[] logItem =
//dr.ItemArray = new string[] { padLogEntry.TimeGenerated.
// padLogEntry.TimeGenerated.
// padLogEntry.Category.ToStr
// padLogEntry.UserName.ToStr
dsLog.Tables[0].Rows.Add(d
}
}
int rows = dsLog.Tables[0].Rows.Count
ReportPreview logPreview = new ReportPreview();
string reportPath = Application.StartupPath + "\\" + "EventLogReport.rpt";
logPreview.crViewer.Report
logPreview.crViewer.Refres
logPreview.crViewer.Refres
if (ckbPreview.Checked == true)
{
logPreview.ShowDialog();
}
else
{
logPreview.crViewer.PrintR
}
//myDoc.Dispose();
logPreview.Dispose();
//All done, clean up
dsLog.Tables.Clear();
dsLog.Dispose();
GC.Collect();
Cursor = Cursors.Default;
}
ASKER
Yes I am using release 2. Thank you.
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
mlmcc
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
mlmcc
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://www.businessobjects.com/products/reporting/crystalreports/compatibility_vs2005.asp
mlmcc