Skip to Content
0
Former Member
Jul 26, 2010 at 03:49 PM

How can avoid the problem of Parameter Prompting when I submitting ?

37 Views

I am developing web application in visual studio 2008 in csharp.How can avoid the issue or problem of Parameter Prompting when I send parameters programaticaly or dyanmicaly? I am sending the values from .net web form to crystal report but it is still asking for parameters. so when i submit second time that is when the reports is being genereated. How can i solve this problem. Please help. The code Iam using is below.

1. using System;

2. using System.Collections;

3. using System.Configuration;

4. using System.Data;

5. using System.Linq;

6. using System.Web;

7. using System.Web.Security;

8. using System.Web.UI;

9. using System.Web.UI.HtmlControls;

10. using System.Web.UI.WebControls;

11. using System.Web.UI.WebControls.WebParts;

12. using System.Xml.Linq;

13. using System.Data.OleDb;

14. using System.Data.OracleClient;

15. using CrystalDecisions.Shared;

16. using CrystalDecisions.CrystalReports.Engine;

17. using CrystalDecisions.Web;

18.

19.

20. public partial class OracleReport : System.Web.UI.Page

21. {

22. CrystalReportViewer crViewer = new CrystalReportViewer();

23. //CrystalReportSource crsource = new CrystalReportSource();

24. int nItemId;

25.

26. protected void Page_Load(object sender, EventArgs e)

27. {

28. //Database Connection

29. ConnectionInfo ConnInfo = new ConnectionInfo();

30. {

31. ConnInfo.ServerName = "127.0.0.1";

32. ConnInfo.DatabaseName = "Xcodf";

33. ConnInfo.UserID = "HR777";

34. ConnInfo.Password = "zghshshs";

35. }

36. // For Each Logon parameters

37. foreach (TableLogOnInfo cnInfo in this.CrystalReportViewer1.LogOnInfo)

38. {

39. cnInfo.ConnectionInfo = ConnInfo;

40.

41. }

42.

43.

44.

45.

46.

47.

48. //Declaring varibles

49. nItemId = int.Parse(Request.QueryString.Get("ItemId"));

50. //string strStartDate = Request.QueryString.Get("StartDate");

51. //int nItemId = 20;

52. string strStartDate = "23-JUL-2010";

53.

54. // object declration

55. CrystalDecisions.CrystalReports.Engine.Database crDatabase;

56. CrystalDecisions.CrystalReports.Engine.Table crTable;

57.

58.

59. TableLogOnInfo dbConn = new TableLogOnInfo();

60.

61. // new report document object

62. ReportDocument oRpt = new ReportDocument();

63.

64. // loading the ItemReport in report document

65. oRpt.Load("C:
Inetpub
wwwroot
cryreport
CrystalReport1.rpt");

66.

67. // getting the database, the table and the LogOnInfo object which holds login onformation

68. crDatabase = oRpt.Database;

69.

70. // getting the table in an object array of one item

71. object[] arrTables = new object[1];

72. crDatabase.Tables.CopyTo(arrTables, 0);

73.

74. // assigning the first item of array to crTable by downcasting the object to Table

75. crTable = (CrystalDecisions.CrystalReports.Engine.Table)arrTables[0];

76.

77. dbConn = crTable.LogOnInfo;

78.

79. // setting values

80. dbConn.ConnectionInfo.DatabaseName = "Xcodf";

81. dbConn.ConnectionInfo.ServerName = "127.0.0.1";

82. dbConn.ConnectionInfo.UserID = "HR777";

83. dbConn.ConnectionInfo.Password = "zghshshs";

84.

85. // applying login info to the table object

86. crTable.ApplyLogOnInfo(dbConn);

87.

88.

89.

90.

91.

92.

93. crViewer.RefreshReport();

94.

95. // defining report source

96. crViewer.ReportSource = oRpt;

97. //CrystalReportSource1.Report = oRpt;

98.

99. // so uptill now we have created everything

100. // what remains is to pass parameters to our report, so it

101. // shows only selected records. so calling a method to set

102. // those parameters.

103. setReportParameters();

104. }

105.

106. private void setReportParameters()

107. {

108.

109. // all the parameter fields will be added to this collection

110. ParameterFields paramFields = new ParameterFields();

111. //ParameterFieldDefinitions ParaLocationContainer = new ParameterFieldDefinitions();

112. //ParameterFieldDefinition ParaLocation = new ParameterFieldDefinition();

113.

114. // the parameter fields to be sent to the report

115. ParameterField pfItemId = new ParameterField();

116. //ParameterField pfStartDate = new ParameterField();

117. //ParameterField pfEndDate = new ParameterField();

118.

119. // setting the name of parameter fields with wich they will be recieved in report

120.

121. pfItemId.ParameterFieldName = "RegionID";

122.

123. //pfStartDate.ParameterFieldName = "StartDate";

124. //pfEndDate.ParameterFieldName = "EndDate";

125.

126. // the above declared parameter fields accept values as discrete objects

127. // so declaring discrete objects

128. ParameterDiscreteValue dcItemId = new ParameterDiscreteValue();

129. //ParameterDiscreteValue dcStartDate = new ParameterDiscreteValue();

130. //ParameterDiscreteValue dcEndDate = new ParameterDiscreteValue();

131.

132. // setting the values of discrete objects

133.

134.

135. dcItemId.Value = nItemId;

136.

137. //dcStartDate.Value = DateTime.Parse(strStartDate);

138. //dcEndDate.Value = DateTime.Parse(strEndDate);

139.

140. // now adding these discrete values to parameters

141. //paramField.HasCurrentValue = true;

142.

143.

144.

145. //pfItemId.CurrentValues.Clear();

146. int valueIDD = int.Parse(Request.QueryString.Get("ItemId").ToString());

147. pfItemId.Name = valueIDD.ToString();

148.

149. pfItemId.CurrentValues.Add(dcItemId);

150. //ParaLocation.ApplyCurrentValues;

151. pfItemId.HasCurrentValue = true;

152.

153. //pfStartDate.CurrentValues.Add(dcStartDate);

154. //pfEndDate.CurrentValues.Add(dcEndDate);

155.

156. // now adding all these parameter fields to the parameter collection

157. paramFields.Add(pfItemId);

158.

159. //paramFields.Add(pfStartDate);

160. //paramFields.Add(pfEndDate);

161. /////////////////////

162. //Formula from Crystal

163. //crViewer.SelectionFormula = "{COUNTRIES.REGION_ID} = " + int.Parse(Request.QueryString.Get("ItemId")) + "";

164. crViewer.RefreshReport();

165. // finally add the parameter collection to the crystal report viewer

166. crViewer.ParameterFieldInfo = paramFields;

167.

168.

169.

170. }

171. }