EDN Admin
Well-known member
Hi, Im trying to pass multiple paramaters from C# program to crystal reports and save that file as pdf. Everything works if I pass one value for one of the parameters. However, what Im trying to do is to have checkboxes that contains values that I
want to pass. If checkbox is checked pass that paramater generate the pdf and save it.
Heres the code. It ONLY works if I pass only ONE value for paramater CLIENTID.
<pre class="prettyprint namespace BillingTool
{
public partial class Form1 : Form
{
ReportDocument cryRpt = new ReportDocument();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
cryRpt.Load(@"r:\testreport.rpt");
}
private void btnshowreport_Click(object sender, EventArgs e)
{
string[] values = { "MEDI0003", "GECA0006", "NCRC0002"};
TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
ConnectionInfo crConnectionInfo = new ConnectionInfo();
Tables CrTables;
ParameterFieldDefinitions crParameterFieldDefinitions;
ParameterFieldDefinition crParameterFieldDefinition;
ParameterValues crParameterValues = new ParameterValues();
ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();
crParameterDiscreteValue.Value = dateTimePicker1.Value;
crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields;
crParameterFieldDefinition = crParameterFieldDefinitions["StartDate"];
crParameterValues = crParameterFieldDefinition.CurrentValues;
crParameterValues.Clear();
crParameterValues.Add(crParameterDiscreteValue);
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);
<span class="x_Apple-tab-span" style="white-spacere //doesnt work this way <span class="x_Apple-tab-span" style="white-spacere //if I change values.ToString() to values[0] it will work for one value<span class="x_Apple-tab-span" style="white-spacere
crParameterDiscreteValue.Value = values.ToString();
crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields;
crParameterFieldDefinition = crParameterFieldDefinitions["ClientID"];
crParameterValues = crParameterFieldDefinition.CurrentValues;
crParameterValues.Clear();
crParameterValues.Add(crParameterDiscreteValue);
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);
crParameterDiscreteValue.Value = dateTimePicker2.Value;
crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields;
crParameterFieldDefinition = crParameterFieldDefinitions["EndDate"];
crParameterValues = crParameterFieldDefinition.CurrentValues;
crParameterValues.Add(crParameterDiscreteValue);
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);
crConnectionInfo.ServerName = "OWSQL2";
crConnectionInfo.DatabaseName = "Billing";
crConnectionInfo.UserID = "RptUser";
crConnectionInfo.Password = "pass";
CrTables = cryRpt.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
{
crtableLogoninfo = CrTable.LogOnInfo;
crtableLogoninfo.ConnectionInfo = crConnectionInfo;
CrTable.ApplyLogOnInfo(crtableLogoninfo);
}
crystalReportViewer1.ReportSource = cryRpt;
crystalReportViewer1.Refresh();
}
private void btnconvert_Click(object sender, EventArgs e)
{
try
{
ExportOptions CrExportOptions;
DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();
CrDiskFileDestinationOptions.DiskFileName = @"C:UserstestDesktopfile.pdf";
CrExportOptions = cryRpt.ExportOptions;
{
CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
CrExportOptions.FormatOptions = CrFormatTypeOptions;
}
cryRpt.Export();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
} [/code]
<br/>
Any ideas on how I can fix this? I dont necessarily need to show this in Crystal Report Viewer. All I want is to generate a PDF from those specified paramaters.
Thanks.
View the full article
want to pass. If checkbox is checked pass that paramater generate the pdf and save it.
Heres the code. It ONLY works if I pass only ONE value for paramater CLIENTID.
<pre class="prettyprint namespace BillingTool
{
public partial class Form1 : Form
{
ReportDocument cryRpt = new ReportDocument();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
cryRpt.Load(@"r:\testreport.rpt");
}
private void btnshowreport_Click(object sender, EventArgs e)
{
string[] values = { "MEDI0003", "GECA0006", "NCRC0002"};
TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
ConnectionInfo crConnectionInfo = new ConnectionInfo();
Tables CrTables;
ParameterFieldDefinitions crParameterFieldDefinitions;
ParameterFieldDefinition crParameterFieldDefinition;
ParameterValues crParameterValues = new ParameterValues();
ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();
crParameterDiscreteValue.Value = dateTimePicker1.Value;
crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields;
crParameterFieldDefinition = crParameterFieldDefinitions["StartDate"];
crParameterValues = crParameterFieldDefinition.CurrentValues;
crParameterValues.Clear();
crParameterValues.Add(crParameterDiscreteValue);
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);
<span class="x_Apple-tab-span" style="white-spacere //doesnt work this way <span class="x_Apple-tab-span" style="white-spacere //if I change values.ToString() to values[0] it will work for one value<span class="x_Apple-tab-span" style="white-spacere
crParameterDiscreteValue.Value = values.ToString();
crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields;
crParameterFieldDefinition = crParameterFieldDefinitions["ClientID"];
crParameterValues = crParameterFieldDefinition.CurrentValues;
crParameterValues.Clear();
crParameterValues.Add(crParameterDiscreteValue);
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);
crParameterDiscreteValue.Value = dateTimePicker2.Value;
crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields;
crParameterFieldDefinition = crParameterFieldDefinitions["EndDate"];
crParameterValues = crParameterFieldDefinition.CurrentValues;
crParameterValues.Add(crParameterDiscreteValue);
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);
crConnectionInfo.ServerName = "OWSQL2";
crConnectionInfo.DatabaseName = "Billing";
crConnectionInfo.UserID = "RptUser";
crConnectionInfo.Password = "pass";
CrTables = cryRpt.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
{
crtableLogoninfo = CrTable.LogOnInfo;
crtableLogoninfo.ConnectionInfo = crConnectionInfo;
CrTable.ApplyLogOnInfo(crtableLogoninfo);
}
crystalReportViewer1.ReportSource = cryRpt;
crystalReportViewer1.Refresh();
}
private void btnconvert_Click(object sender, EventArgs e)
{
try
{
ExportOptions CrExportOptions;
DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();
CrDiskFileDestinationOptions.DiskFileName = @"C:UserstestDesktopfile.pdf";
CrExportOptions = cryRpt.ExportOptions;
{
CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
CrExportOptions.FormatOptions = CrFormatTypeOptions;
}
cryRpt.Export();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
} [/code]
<br/>
Any ideas on how I can fix this? I dont necessarily need to show this in Crystal Report Viewer. All I want is to generate a PDF from those specified paramaters.
Thanks.
View the full article