Visual Studio Development Bookmark and Share   
 index > Crystal Reports for Visual Studio > SetParameterValue() function. - String vs. Number!
 

SetParameterValue() function. - String vs. Number!

Hi, I am creating a report and inserting values by SetParameterValue() function.
When the parameter is a string it's work fine(When I am show this reports on a viewer at other application),
When some of the parameters are a number it'sask my to insert this parameters again(when I am show it) and makeme to login to the database.(Which not happen with string parameter only).
My code is below, Can any one have any idea?
Thanks,
Amos
//////////////////////////////////////////////////////
public class reportGenerator
{
public reportGenerator(string reportTemplate, string reportResults, ListDictionary parameters)
{
//Instantiate variables
ReportDocument reportDocument = new ReportDocument();
reportDocument.Load(reportTemplate);
// Database Access
ConnectionInfo connectionInfo = new ConnectionInfo();
connectionInfo.ServerName = "ServerName";
connectionInfo.DatabaseName = "DBName";
connectionInfo.UserID = "UserId";
connectionInfo.Password = "UserPassword";
connectionInfo.IntegratedSecurity = false;
SetDBLogonForReport(connectionInfo, reportDocument);
reportDocument.SetDatabaseLogon("UserId", "UserPassword", "ServerName", "DBName", false);
foreach (System.Collections.DictionaryEntry param in parameters)
reportDocument.SetParameterValue((string)param.Key, param.Value);
reportDocument.SaveAs(reportResults, true);
}
private void SetDBLogonForReport(ConnectionInfo connectionInfo, ReportDocument reportDocument)
{
Tables tables = reportDocument.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables)
{
TableLogOnInfo tableLogonInfo = table.LogOnInfo;
tableLogonInfo.ConnectionInfo = connectionInfo;
table.ApplyLogOnInfo(tableLogonInfo);
}
}
}
AmosAssis  Sunday, December 28, 2008 7:38 AM
Hi,
I finally understood what is wrong,Some of the reports are build with sub reports in them, so the the parameters didn't set by above code.
Thanks to all.
Amos
  • Marked As Answer byAmosAssis Wednesday, December 31, 2008 2:04 PM
  •  
AmosAssis  Wednesday, December 31, 2008 1:38 PM
Hi There,

Are you passing the parameters in as numbers? Try passing them in as numbers, not as strings.
Chad Kapatch  Monday, December 29, 2008 10:37 PM
o.k.
What I did is this:
////////////////////////////////////////
double Num = 0;
bool isNum = false;
ParameterDiscreteValue paramValue;
foreach (System.Collections.DictionaryEntry param in parameters)
{
isNum = double.TryParse((string)param.Value, out Num);
if (isNum)
{
paramValue = new ParameterDiscreteValue();
paramValue.Value = Convert.ToDecimal(param.Value);
reportDocument.SetParameterValue((string)param.Key, paramValue.Value);
}
else
reportDocument.SetParameterValue((string)param.Key, param.Value);
}
////////////////////////////////////////
But the problem stay. Any other idea?
Thanks, Amos
AmosAssis  Tuesday, December 30, 2008 1:29 PM
Hi,
I finally understood what is wrong,Some of the reports are build with sub reports in them, so the the parameters didn't set by above code.
Thanks to all.
Amos
  • Marked As Answer byAmosAssis Wednesday, December 31, 2008 2:04 PM
  •  
AmosAssis  Wednesday, December 31, 2008 1:38 PM

You can use google to search for other answers

Custom Search

More Threads

• Logon Failed Message
• How a report looks from one machine to the next
• Where is the section_format event in CR with VS 2005 ??? Please!!!
• Database View and Untyped Dataset in crystal reports
• Visual Studio 2008 and Crystal 9.2?
• After install of Visual Studio 2003 SP1 get an error opening a project file. Error says need to update a project to Crystal X.
• Detail with fixed size
• Creating a DataSet with parameters Report using SQL CE
• Graph not showing on website.
• Exporting Crystal Reports to Excel...