Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

C#, Crystal Report question...

Status
Not open for further replies.

hne

Programmer
Oct 16, 2003
38
0
0
US
Hello,
I have an application written in C# that I am using Crystal Reports to view my report. When ever I call the viewer (i.e. crViewer1.Show()), I get the error, "specified argument was out of the range of valid values. Parameter name: Year, Month, and Day parameters describe an unrepresentable DateTime". Thanks for you help.
 
Where do you set your parameters? In code? In the report?

Do you have the rest of the code example that we can see.
 
I am using Stored Procedures. My parameters are set in the report. I pass the values from my code to the parameters. I have two codes, the first is the primary code that creates the CR object and calls the CR code. Below is a sample of my code DisplayProfile.cs:
private void Display_Click(object sender, System.EventArgs e)
{
try{
display_profile.CrystalReportViewer1 crViewer1 = new CrystalReportViewer1();
crViewer1.Show();
}
catch (Exception ex) {
statusBar1.Text = "Error: " + ex.Message.ToString();
}
}

The second is what I called CrystalReportViewer1.cs. This code call set my parameter values in the report to be displayed.



using System;
using System.Drawing;
using System.Data.SqlClient;
using System.Collections;
using System.Data;
using System.ComponentModel;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System.Windows.Forms;

using ConfigurationXml;
using common;

namespace display_profile
{
public class CrystalReportViewer1 : System.Windows.Forms.Form {
private SqlTools sqlTools;
private bool isLoggedOn = false;
private ReportDocument crDocument = new ReportDocument();
private Database crDatabase;
private Tables crTables;
private Table crTable;
private TableLogOnInfo crTableLogOnInfo;
private ConnectionInfo crConnectionInfo;
private ParameterFieldDefinitions crPDefinitions;
private ParameterFieldDefinition crPDefinition;
private ParameterValues crPValues;
protected SqlCommand cmdGateProfile;
protected ParameterField crPField = new ParameterField();
protected ParameterFields crPFields = new ParameterFields();
protected ParameterDiscreteValue crPDValue = new ParameterDiscreteValue();

private CrystalDecisions.Windows.Forms.CrystalReportViewer crystalReportViewer2;
private display_profile.OA_Profiles oA_Profiles1;
private System.ComponentModel.Container components = null;

public CrystalReportViewer1(SqlTools sqlTools_in) {
InitializeComponent();
sqlTools = sqlTools_in;
}

protected override void Dispose( bool disposing ) {
if( disposing ){
if(components != null) {
components.Dispose();
}
}
base.Dispose( disposing );
}

private void crystalReportViewer2_Load(object sender, System.EventArgs e)
{
if (!isLoggedOn)
SetReportParameters();
}

protected void SetReportParameters()
{
int idx;
string str = null;
DateTime dt = new DateTime();

try {
crDocument.Load(crystalReportViewer2.ReportSource.ToString()); // load report...
crConnectionInfo = sqlTools.GetCrConnectionInfo();
crConnectionInfo.ServerName = "SATLRCCDLDB15";
crConnectionInfo.DatabaseName = "oadb";
crConnectionInfo.UserID = "oauser";
crConnectionInfo.Password = "elmwood";
crDatabase = crDocument.Database;
crTables = crDatabase.Tables;

// loop through all the tables and apply the connection into to each table...
for (int i = 0; i < crTables.Count; i++)
{
crTable = crTables;
crTableLogOnInfo = crTable.LogOnInfo;
crTableLogOnInfo.ConnectionInfo = crConnectionInfo;
crTable.ApplyLogOnInfo(crTableLogOnInfo);
}
isLoggedOn = true;
str = DisplayProfile.myDoW.Remove(0, 2);
idx = Convert.ToInt32(DisplayProfile.myDoW.Remove(1, DisplayProfile.myDoW.Length - 1));

crPDefinitions = crDocument.DataDefinition.ParameterFields;
crPDefinition = crPDefinitions["@start_date"];
crPValues = crPDefinition.CurrentValues;
crPDValue.Value = DisplayProfile.startDate.ToString("MM-dd-yyyy");
crPValues.Add(crPDValue);
crPDefinition.ApplyCurrentValues(crPValues);
crDocument.DataDefinition.ParameterFields.MoveNext();

crPDefinition = crPDefinitions["@end_date"];
crPValues = crPDefinition.CurrentValues;
crPValues.Clear();
crPDValue.Value = DisplayProfile.endDate.ToString("MM-dd-yyyy");
crPValues.Add(crPDValue);
crPDefinition.ApplyCurrentValues(crPValues);
crDocument.DataDefinition.ParameterFields.MoveNext();

crDocument.SetDatabaseLogon(crConnectionInfo.UserID, crConnectionInfo.Password, crConnectionInfo.ServerName, crConnectionInfo.DatabaseName);
crystalReportViewer2.ReportSource = crDocument;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
finally
{
sqlTools.DisposeSqlConnection();
}
}

Whenever my code gets to the 'crViewer1.Show()' method (in my DiaplayProfile code) and call my CrystalReportViewr1 code, I get the error mentioned above. Thank you. Your help is very appreciated.
 
It turned out that the path for my report had changed. Thanks for you help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top