Hi,
I've got a Crystal Report that gets some data from a stored procedure and I
need to set some params of the proc at runtime.
But no matter what I do, I cannot get the report to eat the params - it
keeps showing an error that the proc needs to have it's params initialized.
Code's something like:
ConnectionInfo ci = new ConnectionInfo();
ci.ServerName = sqlServer;
ci.DatabaseName = sqlDatabase;
ci.UserID = sqlUser;
ci.Password = sqlPassword;
TableLogOnInfo ti = new TableLogOnInfo();
ti.ConnectionInfo = ci;
ReportDocument doc = new ReportDocument();
doc.Load(reportDoc); // Some .rpt file
doc.SetDatabaseLogon(sqlUser, sqlPassword);
foreach(Table t in doc.Database.Tables)
{
t.ApplyLogOnInfo(ti);
if(!t.TestConnectivity())
{
return -2;
}
}
ParameterFieldDefinitions pfds = doc.DataDefinition.ParameterFields;
for(int i = 0; i < 3; i++)
{
string name = "";
string value = "";
switch(i)
{
case 0:
name = "@ItemName";
value = "ZZZZZ";
break;
case 1:
name = "@ItemCount";
value = "10";
break;
case 2:
name = "@ItemOption";
value = "0";
break;
}
ParameterDiscreteValue pdv = new ParameterDiscreteValue();
pdv.Value = value;
ParameterValues pvs = new ParameterValues();
pvs.Add(pdv);
ParameterFieldDefinition pfd = pfds[name];
pfd.ApplyCurrentValues(pvs);
}
_reportViewer.ReportSource = doc;
Running through the params before setting the report on the viewer tells me
that all params has a current value!
Where am I getting wrong, or what am I missing to do ??
Thanks in advance
Soren