Writing Code
 Crystal Reports Forum : Crystal Reports for Visual Studio 2005 and Newer : Writing Code
Message Icon Topic: Parameter Field with C# Post Reply Post New Topic
Author Message
mixarstudio
Newbie
Newbie
Avatar

Joined: 11 May 2009
Online Status: Offline
Posts: 3
Quote mixarstudio Replybullet Topic: Parameter Field with C#
    Posted: 17 May 2009 at 7:24am


i have some problem when i pass values to my crystal report page

basically, on page load first time i can bind  and show the report

but the problem is here...

when i click on export, print, next/previous page, zoom, navigate

my page told me "Missing parameter value"

here is all of my code

1    using System;
2 using System.Data;
3 using System.Data.SqlClient;
4 using System.Web.Configuration;
5 using System.Configuration;
6 using System.Web;
7 using System.Web.Security;
8 using System.Web.UI;
9 using System.Web.UI.WebControls;
10 using System.Web.UI.WebControls.WebParts;
11 using System.Web.UI.HtmlControls;
12 using CrystalDecisions.CrystalReports.Engine;
13 using CrystalDecisions.Shared;
14 using dsShippingSummByProductTableAdapters;
15
16 public partial class Admin_AdminCrShippingSummByProduct : System.Web.UI.Page
17 {
18 string fDate;
19 string tDate;
20 string viewBy;
21 string fullName;
22 ReportDocument report = new ReportDocument();
23 ParameterFields pfields = new ParameterFields();
24
25 protected void Page_Load(object sender, EventArgs e)
26 {
27 fDate = Session["FDATE"].ToString();
28 tDate = Session["TDATE"].ToString();
29 viewBy = Session["VIEWBY"].ToString();
30
31 string staffID = "0000000001"; //Integrate remove this line
32 Session["staffID"] = staffID; //Integrate remove this line
33 Session["StaffID"] = Session["staffID"];
34
35 string strConn = "Data Source=MIXAR-PC;Initial Catalog=StockProductInfo;Integrated Security=True";
36
37 SqlConnection Conn = new SqlConnection(strConn);
38 if (Conn.State == ConnectionState.Open)
39 {
40 Conn.Close();
41 }
42 Conn.ConnectionString = strConn;
43 Conn.Open();
44
45 string sqlStaffName = "select Staff_FName, Staff_LName ";
46 sqlStaffName += "from masStaff ";
47 sqlStaffName += "where Staff_ID = " + Session["StaffID"].ToString();
48
49 SqlDataAdapter daStaff = new SqlDataAdapter(sqlStaffName, Conn);
50 DataSet dsStaff = new DataSet();
51 daStaff.Fill(dsStaff, "Staff");
52
53 string fName = dsStaff.Tables["Staff"].Rows[0]["Staff_FName"].ToString();
54 string lName = dsStaff.Tables["Staff"].Rows[0]["Staff_LName"].ToString();
55 fullName = fName + " " + lName;
56
57 ParameterField pfieldFDATE = new ParameterField();
58 ParameterDiscreteValue disValFDATE = new ParameterDiscreteValue();
59 disValFDATE.Value = DateTime.Parse(fDate);
60 pfieldFDATE.Name = "FDate";
61 pfieldFDATE.CurrentValues.Add(disValFDATE);
62
63 ParameterField pfieldTDATE = new ParameterField();
64 ParameterDiscreteValue disValTDATE = new ParameterDiscreteValue();
65 disValTDATE.Value = DateTime.Parse(tDate);
66 pfieldTDATE.Name = "TDate";
67 pfieldTDATE.CurrentValues.Add(disValTDATE);
68
69 ParameterField pfieldVIEWBY = new ParameterField();
70 ParameterDiscreteValue disValVIEWBY = new ParameterDiscreteValue();
71 disValVIEWBY.Value = viewBy;
72 pfieldVIEWBY.Name = "ViewBy";
73 pfieldVIEWBY.CurrentValues.Add(disValVIEWBY);
74
75 ParameterField pfieldSTAFF = new ParameterField();
76 ParameterDiscreteValue disValSTAFF = new ParameterDiscreteValue();
77 disValSTAFF.Value = fullName;
78 pfieldSTAFF.Name = "StaffName";
79 pfieldSTAFF.CurrentValues.Add(disValSTAFF);
80
81 pfields.Add(pfieldFDATE);
82 pfields.Add(pfieldTDATE);
83 pfields.Add(pfieldVIEWBY);
84 pfields.Add(pfieldSTAFF);
85
86 CrystalReportViewer1.ParameterFieldInfo = pfields;
87
88 crvBinding();
89 }
90 private void crvBinding()
91 {
92 report.Load(Server.MapPath("../SalesReport/ShippingSummByProductReport.rpt"));
93
94 SPShipSummByProductTableAdapter adapter = new SPShipSummByProductTableAdapter();
95 CrystalReportManager crManager = new CrystalReportManager(report, adapter.GetData(fDate,tDate));
96
97 CrystalReportViewer1.ReportSource = crManager.Report;
98 CrystalReportViewer1.Visible = true;
99 }
100 protected void CrystalReportViewer1_ViewZoom(object source, CrystalDecisions.Web.ZoomEventArgs e)
101 {
102 crvBinding();
103 }
104 protected void CrystalReportViewer1_Search(object source, CrystalDecisions.Web.SearchEventArgs e)
105 {
106 crvBinding();
107 }
108 protected void CrystalReportViewer1_Navigate(object source, CrystalDecisions.Web.NavigateEventArgs e)
109 {
110 crvBinding();
111 }
112 }
113

how can i pass values to parameter fields

when i click on export, print, previous/next page, navigate zoom


can anyone help me to correct my code

to support all functions(export, print, previous/next page, navigate zoom) ?

or has another way to pass value

thanks for the answer
IP IP Logged
Bit-Smacker
Newbie
Newbie


Joined: 17 Jun 2009
Location: United States
Online Status: Offline
Posts: 1
Quote Bit-Smacker Replybullet Posted: 17 Jun 2009 at 3:20pm
You are loading the same page every time, which is probably clearing any selections that you are capturing in session variables.
 
Try adding this block inside your Page_Load function and move your session value assignments into it:
 
if (!Page.IsPostBack)
{
     // session variable assignments
}
 
This will ensure that the variable assignments are only made upon the first load of the page.  Subsequent loads from postback will not execute that code.
 
Originally posted by mixarstudio

i have some problem when i pass values to my crystal report page

basically, on page load first time i can bind  and show the report



Edited by Bit-Smacker - 17 Jun 2009 at 3:23pm
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.035 seconds.