|
-
Jan 26th, 2006, 11:34 AM
#1
Thread Starter
Frenzied Member
vb convert c#, passing parameter crystal rpts [*Resolved*]
Hello,
I have a vb code which l am trying to convert to c# and having many problems with it. PFD = rpt.DataDefinition.ParameterFields.Item("@dt"). In c# there is not a parameterFields method called Item. So i am not sure how do l get the name of my parameter that is in the crystal report viewer.
Can anyone help me convert this code to c#.
Code:
Imports CrystalDecisions.Shared
Imports CrystalDecisions.CrystalReports.Engine
Dim mDate As DataTime = #01/01/2005#
Dim rpt As New CrystalReport1
Dim PFD As ParameterFieldDefinition
Dim PValues As ParameterValues
Dim Parm As ParameterDiscreteValue
PValues = New ParameterValues
PFD = rpt.DataDefinition.ParameterFields.Item("@dt")
Parm = New ParameterDiscreteValue
Parm.Value = mDate
PValues.Add(Parm)
PFD.ApplyCurrentValues(PValues)
CrystalReportViewer1.ReportSource = rpt
Thanks in advance,
Steve
Edit: Added [code][/code] tags for clarity. - Hack
Last edited by steve_rm; Jan 27th, 2006 at 07:01 AM.
steve
-
Jan 26th, 2006, 11:45 AM
#2
Re: vb convert c#, passing parameter crystal rpts
Instead of .Item("@dt"), you could try just ["@dt"];
(without the .Item, and square brackets)
-
Jan 26th, 2006, 05:30 PM
#3
Re: vb convert c#, passing parameter crystal rpts
In VB.NET the Item property is often the default property, which means you can omit the property name, i.e.
VB Code:
PFD = rpt.DataDefinition.ParameterFields.Item("@dt")
could be written
VB Code:
PFD = rpt.DataDefinition.ParameterFields("@dt")
In C# the equivalent of a default property is an indexer. When using an indexer I believe that you MUST omit the property name, so the C# code becomes
Code:
PFD = rpt.DataDefinition.ParameterFields["@dt"];
-
Jan 26th, 2006, 09:18 PM
#4
Re: vb convert c#, passing parameter crystal rpts
Instant C# produces:
using CrystalDecisions.Shared;
using CrystalDecisions.CrystalReports.Engine;
public void test()
{
DataTime mDate = DateTime.Parse("01/01/2005");
CrystalReport1 rpt = new CrystalReport1();
ParameterFieldDefinition PFD = null;
ParameterValues PValues = null;
ParameterDiscreteValue Parm = null;
PValues = new ParameterValues();
PFD = rpt.DataDefinition.ParameterFields["@dt"];
Parm = new ParameterDiscreteValue();
Parm.Value = mDate;
PValues.Add(Parm);
PFD.ApplyCurrentValues(PValues);
CrystalReportViewer1.ReportSource = rpt;
}
-
Jan 27th, 2006, 07:00 AM
#5
Thread Starter
Frenzied Member
Re: vb convert c#, passing parameter crystal rpts
Thanks for all your help.
PFD = rpt.DataDefinition.ParameterFields["dt"];
Have to take out the @ sign of an error message says field name does not exist.
Thanks,
Steve
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|