Please help me, I'm too much lost because I can not pass ParameterFields to the CrystallReportViewer, It always give me the error
"Object reference not set to an instance of an object."
Only simple report and only one ParameterFields . Nothing else:
The code I pass parameter is copied from the MSDN help as the following:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
crystalReportViewer1.ReportSource =
"http://localhost/ec/reports/CrystalReport1Service.asmx";
try
{
SetParameterFieldInfo("x1", "xxxx");
}
catch (Exception)
{
throw;
}
}
private void SetParameterFieldInfo(String fieldName, String fieldValue)
{
CrystalDecisions.Shared.ParameterDiscreteValue parameterDiscreteValue = new CrystalDecisions.Shared.ParameterDiscreteValue();
parameterDiscreteValue.Value = fieldValue;
CrystalDecisions.Shared.ParameterValues currentParameterValues = new CrystalDecisions.Shared.ParameterValues();
currentParameterValues.Add(parameterDiscreteValue);
CrystalDecisions.Shared.ParameterField parameterField = new CrystalDecisions.Shared.ParameterField();
parameterField.Name = fieldName;
parameterField.CurrentValues = currentParameterValues;
//if (parameterField.HasCurrentValue)
// MessageBox.Show(parameterField.);
CrystalDecisions.Shared.ParameterFields parameterFields = new CrystalDecisions.Shared.ParameterFields();
parameterFields.Add(parameterField);
crystalReportViewer1.ParameterFieldInfo = parameterFields;
}
}
As you can see from the above code it is very straight. I always get the following exception:
at CrystalDecisions.Windows.Forms.ParameterFieldInfo.get_isDCP()
at CrystalDecisions.Windows.Forms.ParameterValueEditControl.Start()
at CrystalDecisions.Windows.Forms.ParameterUnit.AddEditControl(ParameterValue pv)
at CrystalDecisions.Windows.Forms.ParameterUnit.UpdateControls()
at CrystalDecisions.Windows.Forms.ParameterUnit.set_ParameterFieldInfo(ParameterFieldInfo value)
at CrystalDecisions.Windows.Forms.InteractiveParameterPanel.ShowParameters()
at CrystalDecisions.Windows.Forms.CrystalReportViewer.ShowInteractiveParameters()
at CrystalDecisions.Windows.Forms.CrystalReportViewer.ShowReport()
at CrystalDecisions.Windows.Forms.CrystalReportViewer.OnPaint(PaintEventArgs evtArgs)
at System.Windows.Forms.Control.PaintTransparentBackground(PaintEventArgs e, Rectangle rectangle, Region transparentRegion)
at System.Windows.Forms.ToolStrip.EraseCorners(PaintEventArgs e, Region transparentRegion)
at System.Windows.Forms.ToolStrip.OnPaintBackground(PaintEventArgs e)
at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs)
at System.Windows.Forms.Control.WmPaint(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ToolStrip.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.SafeNativeMethods.UpdateWindow(HandleRef hWnd)
at System.Windows.Forms.Control.Update()
at System.Windows.Forms.ToolStrip.ClearAllSelectionsExcept(ToolStripItem item)
at System.Windows.Forms.ToolStrip.NotifySelectionChange(ToolStripItem item)
at System.Windows.Forms.ToolStripItem.Select()
at System.Windows.Forms.ToolStrip.ChangeSelection(ToolStripItem nextItem)
at System.Windows.Forms.ToolStrip.SelectNextToolStripItem(ToolStripItem start, Boolean forward)
at System.Windows.Forms.ToolStrip.Select(Boolean directed, Boolean forward)
at System.Windows.Forms.Control.SelectNextControl(Control ctl, Boolean forward, Boolean tabStopOnly, Boolean nested, Boolean wrap)
at System.Windows.Forms.ContainerControl.Select(Boolean directed, Boolean forward)
at System.Windows.Forms.Control.SelectNextControl(Control ctl, Boolean forward, Boolean tabStopOnly, Boolean nested, Boolean wrap)
at System.Windows.Forms.Control.SelectNextControlInternal(Control ctl, Boolean forward, Boolean tabStopOnly, Boolean nested, Boolean wrap)
at System.Windows.Forms.Form.set_Active(Boolean value)
at System.Windows.Forms.Form.WmActivate(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)
at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
at System.Windows.Forms.Control.set_Visible(Boolean value)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at testItemCard.Program.Main() in C:\Users\Tariq\Documents\Visual Studio 2008\Projects\testItemCard\testItemCard\Program.cs:line 18
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
Then the report is diplayed propably and the parameters is passed to it but I want to avoid this exception
Please help me to figure out what is wrong, I can send parameters to ReportDocument but when the ReportSource is a Web Service (asmx) It always raise.
For mor explaination:
1- I create a report which has only one string field.
2- The report has only one parameter string olso.
3- I place the parameter in the page header.
4- I create a new Crystal Reports Web Site from Visual Studio 2008.
5- I add the report to the web site.
6- I right click the report and choose "Publish as a web service"
7- I create a windows forms application with CrystalReportViewer1
8- In the form load I set the report source to the auto generated web service using this code only
crystalReportViewer1.ReportSource = "http://localhost/ec/reports/CrystalReport1Service.asmx";
Then I run the application.
CR shows the parameters dialog then raises the exception.
Also if i send the parameter using the crystal report viewer it gives the same exception!!!
My question is If somebody try the steps above then tell me whether the exception is raised in his computer?
Should I make special settings?
Please help me. It is very simple steps. Just do it and tell me the results.
Thanks in advance.