C#怎么把水晶报表显示在crystalReportViewer控件中
要具体过程,比如数据库的DATASET什么的都怎么写。一步步把代码写上就行。报表已经创建好了。我的主要目的是要在这个控件中显示不同的报表。谢谢...
要具体过程,比如数据库的DATASET什么的都怎么写。一步步把代码写上就行。报表已经创建好了。我的主要目的是要在这个控件中显示不同的报表。谢谢
展开
3个回答
推荐于2018-05-07
展开全部
customerReport = new ReportDocument();
string reportPath = Server.MapPath("PrintGif\\CrystalReport.rpt");
customerReport.Load(reportPath);
customerReport.SetDataSource(dt);
ParameterFields paramFields = new ParameterFields();
ParameterField paramField1 = new ParameterField();
ParameterField paramField2 = new ParameterField();
ParameterField paramField3 = new ParameterField();
ParameterField paramField4 = new ParameterField();
ParameterField paramField5 = new ParameterField();
ParameterField paramField6 = new ParameterField();
ParameterField paramField7 = new ParameterField();
ParameterField paramField8 = new ParameterField();
ParameterDiscreteValue discreteVal1 = new ParameterDiscreteValue();
ParameterDiscreteValue discreteVal2 = new ParameterDiscreteValue();
ParameterDiscreteValue discreteVal3 = new ParameterDiscreteValue();
ParameterDiscreteValue discreteVal4 = new ParameterDiscreteValue();
ParameterDiscreteValue discreteVal5 = new ParameterDiscreteValue();
ParameterDiscreteValue discreteVal6 = new ParameterDiscreteValue();
ParameterDiscreteValue discreteVal7 = new ParameterDiscreteValue();
ParameterDiscreteValue discreteVal8 = new ParameterDiscreteValue();
ParameterRangeValue rangeVal = new ParameterRangeValue();
// 设置参数字段的名称,它必须
//和报表中的参数相符。
paramField1.ParameterFieldName = "year";
paramField2.ParameterFieldName = "month";
paramField3.ParameterFieldName = "day";
paramField4.ParameterFieldName = "Hour";
paramField5.ParameterFieldName = "Minute";
paramField6.ParameterFieldName = "sname";
paramField7.ParameterFieldName = "Amount";
paramField8.ParameterFieldName = "CNAmount";
// 设置第一个离散值并将其传递给该参数。
discreteVal1.Value = dt.Rows[0]["TIME"].ToString().Substring(0, 4);
discreteVal2.Value = dt.Rows[0]["TIME"].ToString().Substring(4, 2);
discreteVal3.Value = dt.Rows[0]["TIME"].ToString().Substring(6, 2);
discreteVal4.Value = dt.Rows[0]["TIME"].ToString().Substring(8, 2);
discreteVal5.Value = dt.Rows[0]["TIME"].ToString().Substring(10, 2);
discreteVal6.Value = dt.Rows[0]["name"].ToString();
string Amount = (Convert.ToDouble(dt.Rows[0]["PRC"].ToString()) * Convert.ToDouble(dt.Rows[0]["VOL"].ToString())).ToString();
decimal AmountN = 0;
discreteVal8.Value = PublicClass.ConvertToCn(Amount,out AmountN);
discreteVal7.Value = AmountN;
paramField1.CurrentValues.Add(discreteVal1);
paramField2.CurrentValues.Add(discreteVal2);
paramField3.CurrentValues.Add(discreteVal3);
paramField4.CurrentValues.Add(discreteVal4);
paramField5.CurrentValues.Add(discreteVal5);
paramField6.CurrentValues.Add(discreteVal6);
paramField7.CurrentValues.Add(discreteVal7);
paramField8.CurrentValues.Add(discreteVal8);
// 将该参数添加到参数字段集合。
paramFields.Add(paramField1);
paramFields.Add(paramField2);
paramFields.Add(paramField3);
paramFields.Add(paramField4);
paramFields.Add(paramField5);
paramFields.Add(paramField6);
paramFields.Add(paramField7);
paramFields.Add(paramField8);
// 将参数字段集合放入查看器控件。
CrystalReportViewer1.ReportSource = customerReport;
this.CrystalReportViewer1.ParameterFieldInfo = paramFields;
//设置成 139.7 x 215.9 毫米的纸张,也就是“半刀纸”,约 A4 的一半。
customerReport.PrintOptions.PaperSize = CrystalDecisions.Shared.PaperSize.PaperStatement;
//设置报表方向为横向,注意系统没有真正的“半刀纸”,只有把上述纸张横着看才符合要求。打印时不需要设置为横打
customerReport.PrintOptions.PaperOrientation = CrystalDecisions.Shared.PaperOrientation.Landscape;
CrystalReportViewer1.HasCrystalLogo = false;
CrystalReportViewer1.HasToggleGroupTreeButton = false;
CrystalReportViewer1.HasViewList = false;
try
{
//CrystalReportViewer1.PrintMode = CrystalDecisions.Web.PrintMode.ActiveX;
System.Drawing.Printing.PrintDocument printDocument = new System.Drawing.Printing.PrintDocument();
customerReport.PrintOptions.PrinterName = printDocument.PrinterSettings.PrinterName;
customerReport.PrintToPrinter(1, true, 0, 0);
}
catch
{
}
string reportPath = Server.MapPath("PrintGif\\CrystalReport.rpt");
customerReport.Load(reportPath);
customerReport.SetDataSource(dt);
ParameterFields paramFields = new ParameterFields();
ParameterField paramField1 = new ParameterField();
ParameterField paramField2 = new ParameterField();
ParameterField paramField3 = new ParameterField();
ParameterField paramField4 = new ParameterField();
ParameterField paramField5 = new ParameterField();
ParameterField paramField6 = new ParameterField();
ParameterField paramField7 = new ParameterField();
ParameterField paramField8 = new ParameterField();
ParameterDiscreteValue discreteVal1 = new ParameterDiscreteValue();
ParameterDiscreteValue discreteVal2 = new ParameterDiscreteValue();
ParameterDiscreteValue discreteVal3 = new ParameterDiscreteValue();
ParameterDiscreteValue discreteVal4 = new ParameterDiscreteValue();
ParameterDiscreteValue discreteVal5 = new ParameterDiscreteValue();
ParameterDiscreteValue discreteVal6 = new ParameterDiscreteValue();
ParameterDiscreteValue discreteVal7 = new ParameterDiscreteValue();
ParameterDiscreteValue discreteVal8 = new ParameterDiscreteValue();
ParameterRangeValue rangeVal = new ParameterRangeValue();
// 设置参数字段的名称,它必须
//和报表中的参数相符。
paramField1.ParameterFieldName = "year";
paramField2.ParameterFieldName = "month";
paramField3.ParameterFieldName = "day";
paramField4.ParameterFieldName = "Hour";
paramField5.ParameterFieldName = "Minute";
paramField6.ParameterFieldName = "sname";
paramField7.ParameterFieldName = "Amount";
paramField8.ParameterFieldName = "CNAmount";
// 设置第一个离散值并将其传递给该参数。
discreteVal1.Value = dt.Rows[0]["TIME"].ToString().Substring(0, 4);
discreteVal2.Value = dt.Rows[0]["TIME"].ToString().Substring(4, 2);
discreteVal3.Value = dt.Rows[0]["TIME"].ToString().Substring(6, 2);
discreteVal4.Value = dt.Rows[0]["TIME"].ToString().Substring(8, 2);
discreteVal5.Value = dt.Rows[0]["TIME"].ToString().Substring(10, 2);
discreteVal6.Value = dt.Rows[0]["name"].ToString();
string Amount = (Convert.ToDouble(dt.Rows[0]["PRC"].ToString()) * Convert.ToDouble(dt.Rows[0]["VOL"].ToString())).ToString();
decimal AmountN = 0;
discreteVal8.Value = PublicClass.ConvertToCn(Amount,out AmountN);
discreteVal7.Value = AmountN;
paramField1.CurrentValues.Add(discreteVal1);
paramField2.CurrentValues.Add(discreteVal2);
paramField3.CurrentValues.Add(discreteVal3);
paramField4.CurrentValues.Add(discreteVal4);
paramField5.CurrentValues.Add(discreteVal5);
paramField6.CurrentValues.Add(discreteVal6);
paramField7.CurrentValues.Add(discreteVal7);
paramField8.CurrentValues.Add(discreteVal8);
// 将该参数添加到参数字段集合。
paramFields.Add(paramField1);
paramFields.Add(paramField2);
paramFields.Add(paramField3);
paramFields.Add(paramField4);
paramFields.Add(paramField5);
paramFields.Add(paramField6);
paramFields.Add(paramField7);
paramFields.Add(paramField8);
// 将参数字段集合放入查看器控件。
CrystalReportViewer1.ReportSource = customerReport;
this.CrystalReportViewer1.ParameterFieldInfo = paramFields;
//设置成 139.7 x 215.9 毫米的纸张,也就是“半刀纸”,约 A4 的一半。
customerReport.PrintOptions.PaperSize = CrystalDecisions.Shared.PaperSize.PaperStatement;
//设置报表方向为横向,注意系统没有真正的“半刀纸”,只有把上述纸张横着看才符合要求。打印时不需要设置为横打
customerReport.PrintOptions.PaperOrientation = CrystalDecisions.Shared.PaperOrientation.Landscape;
CrystalReportViewer1.HasCrystalLogo = false;
CrystalReportViewer1.HasToggleGroupTreeButton = false;
CrystalReportViewer1.HasViewList = false;
try
{
//CrystalReportViewer1.PrintMode = CrystalDecisions.Web.PrintMode.ActiveX;
System.Drawing.Printing.PrintDocument printDocument = new System.Drawing.Printing.PrintDocument();
customerReport.PrintOptions.PrinterName = printDocument.PrinterSettings.PrinterName;
customerReport.PrintToPrinter(1, true, 0, 0);
}
catch
{
}
2017-03-04 · 知道合伙人互联网行家
关注
展开全部
customerReport = new ReportDocument();
string reportPath = Server.MapPath("PrintGif\\CrystalReport.rpt");
customerReport.Load(reportPath);
customerReport.SetDataSource(dt);
ParameterFields paramFields = new ParameterFields();
ParameterField paramField1 = new ParameterField();
ParameterField paramField2 = new ParameterField();
ParameterField paramField3 = new ParameterField();
ParameterField paramField4 = new ParameterField();
ParameterField paramField5 = new ParameterField();
ParameterField paramField6 = new ParameterField();
ParameterField paramField7 = new ParameterField();
ParameterField paramField8 = new ParameterField();
ParameterDiscreteValue discreteVal1 = new ParameterDiscreteValue();
ParameterDiscreteValue discreteVal2 = new ParameterDiscreteValue();
ParameterDiscreteValue discreteVal3 = new ParameterDiscreteValue();
ParameterDiscreteValue discreteVal4 = new ParameterDiscreteValue();
ParameterDiscreteValue discreteVal5 = new ParameterDiscreteValue();
ParameterDiscreteValue discreteVal6 = new ParameterDiscreteValue();
ParameterDiscreteValue discreteVal7 = new ParameterDiscreteValue();
ParameterDiscreteValue discreteVal8 = new ParameterDiscreteValue();
ParameterRangeValue rangeVal = new ParameterRangeValue();
// 设置参数字段的名称,它必须
//和报表中的参数相符。
paramField1.ParameterFieldName = "year";
paramField2.ParameterFieldName = "month";
paramField3.ParameterFieldName = "day";
paramField4.ParameterFieldName = "Hour";
paramField5.ParameterFieldName = "Minute";
paramField6.ParameterFieldName = "sname";
paramField7.ParameterFieldName = "Amount";
paramField8.ParameterFieldName = "CNAmount";
// 设置第一个离散值并将其传递给该参数。
discreteVal1.Value = dt.Rows[0]["TIME"].ToString().Substring(0, 4);
discreteVal2.Value = dt.Rows[0]["TIME"].ToString().Substring(4, 2);
discreteVal3.Value = dt.Rows[0]["TIME"].ToString().Substring(6, 2);
discreteVal4.Value = dt.Rows[0]["TIME"].ToString().Substring(8, 2);
discreteVal5.Value = dt.Rows[0]["TIME"].ToString().Substring(10, 2);
discreteVal6.Value = dt.Rows[0]["name"].ToString();
string Amount = (Convert.ToDouble(dt.Rows[0]["PRC"].ToString()) * Convert.ToDouble(dt.Rows[0]["VOL"].ToString())).ToString();
decimal AmountN = 0;
discreteVal8.Value = PublicClass.ConvertToCn(Amount,out AmountN);
discreteVal7.Value = AmountN;
paramField1.CurrentValues.Add(discreteVal1);
paramField2.CurrentValues.Add(discreteVal2);
paramField3.CurrentValues.Add(discreteVal3);
paramField4.CurrentValues.Add(discreteVal4);
paramField5.CurrentValues.Add(discreteVal5);
paramField6.CurrentValues.Add(discreteVal6);
paramField7.CurrentValues.Add(discreteVal7);
paramField8.CurrentValues.Add(discreteVal8);
// 将该参数添加到参数字段集合。
paramFields.Add(paramField1);
paramFields.Add(paramField2);
paramFields.Add(paramField3);
paramFields.Add(paramField4);
paramFields.Add(paramField5);
paramFields.Add(paramField6);
paramFields.Add(paramField7);
paramFields.Add(paramField8);
// 将参数字段集合放入查看器控件。
CrystalReportViewer1.ReportSource = customerReport;
this.CrystalReportViewer1.ParameterFieldInfo = paramFields;
//设置成 139.7 x 215.9 毫米的纸张,也就是“半刀纸”,约 A4 的一半。
customerReport.PrintOptions.PaperSize = CrystalDecisions.Shared.PaperSize.PaperStatement;
//设置报表方向为横向,注意系统没有真正的“半刀纸”,只有把上述纸张横着看才符合要求。打印时不需要设置为横打
customerReport.PrintOptions.PaperOrientation = CrystalDecisions.Shared.PaperOrientation.Landscape;
CrystalReportViewer1.HasCrystalLogo = false;
CrystalReportViewer1.HasToggleGroupTreeButton = false;
CrystalReportViewer1.HasViewList = false;
try
{
//CrystalReportViewer1.PrintMode = CrystalDecisions.Web.PrintMode.ActiveX;
System.Drawing.Printing.PrintDocument printDocument = new System.Drawing.Printing.PrintDocument();
customerReport.PrintOptions.PrinterName = printDocument.PrinterSettings.PrinterName;
customerReport.PrintToPrinter(1, true, 0, 0);
}
catch
{
}
string reportPath = Server.MapPath("PrintGif\\CrystalReport.rpt");
customerReport.Load(reportPath);
customerReport.SetDataSource(dt);
ParameterFields paramFields = new ParameterFields();
ParameterField paramField1 = new ParameterField();
ParameterField paramField2 = new ParameterField();
ParameterField paramField3 = new ParameterField();
ParameterField paramField4 = new ParameterField();
ParameterField paramField5 = new ParameterField();
ParameterField paramField6 = new ParameterField();
ParameterField paramField7 = new ParameterField();
ParameterField paramField8 = new ParameterField();
ParameterDiscreteValue discreteVal1 = new ParameterDiscreteValue();
ParameterDiscreteValue discreteVal2 = new ParameterDiscreteValue();
ParameterDiscreteValue discreteVal3 = new ParameterDiscreteValue();
ParameterDiscreteValue discreteVal4 = new ParameterDiscreteValue();
ParameterDiscreteValue discreteVal5 = new ParameterDiscreteValue();
ParameterDiscreteValue discreteVal6 = new ParameterDiscreteValue();
ParameterDiscreteValue discreteVal7 = new ParameterDiscreteValue();
ParameterDiscreteValue discreteVal8 = new ParameterDiscreteValue();
ParameterRangeValue rangeVal = new ParameterRangeValue();
// 设置参数字段的名称,它必须
//和报表中的参数相符。
paramField1.ParameterFieldName = "year";
paramField2.ParameterFieldName = "month";
paramField3.ParameterFieldName = "day";
paramField4.ParameterFieldName = "Hour";
paramField5.ParameterFieldName = "Minute";
paramField6.ParameterFieldName = "sname";
paramField7.ParameterFieldName = "Amount";
paramField8.ParameterFieldName = "CNAmount";
// 设置第一个离散值并将其传递给该参数。
discreteVal1.Value = dt.Rows[0]["TIME"].ToString().Substring(0, 4);
discreteVal2.Value = dt.Rows[0]["TIME"].ToString().Substring(4, 2);
discreteVal3.Value = dt.Rows[0]["TIME"].ToString().Substring(6, 2);
discreteVal4.Value = dt.Rows[0]["TIME"].ToString().Substring(8, 2);
discreteVal5.Value = dt.Rows[0]["TIME"].ToString().Substring(10, 2);
discreteVal6.Value = dt.Rows[0]["name"].ToString();
string Amount = (Convert.ToDouble(dt.Rows[0]["PRC"].ToString()) * Convert.ToDouble(dt.Rows[0]["VOL"].ToString())).ToString();
decimal AmountN = 0;
discreteVal8.Value = PublicClass.ConvertToCn(Amount,out AmountN);
discreteVal7.Value = AmountN;
paramField1.CurrentValues.Add(discreteVal1);
paramField2.CurrentValues.Add(discreteVal2);
paramField3.CurrentValues.Add(discreteVal3);
paramField4.CurrentValues.Add(discreteVal4);
paramField5.CurrentValues.Add(discreteVal5);
paramField6.CurrentValues.Add(discreteVal6);
paramField7.CurrentValues.Add(discreteVal7);
paramField8.CurrentValues.Add(discreteVal8);
// 将该参数添加到参数字段集合。
paramFields.Add(paramField1);
paramFields.Add(paramField2);
paramFields.Add(paramField3);
paramFields.Add(paramField4);
paramFields.Add(paramField5);
paramFields.Add(paramField6);
paramFields.Add(paramField7);
paramFields.Add(paramField8);
// 将参数字段集合放入查看器控件。
CrystalReportViewer1.ReportSource = customerReport;
this.CrystalReportViewer1.ParameterFieldInfo = paramFields;
//设置成 139.7 x 215.9 毫米的纸张,也就是“半刀纸”,约 A4 的一半。
customerReport.PrintOptions.PaperSize = CrystalDecisions.Shared.PaperSize.PaperStatement;
//设置报表方向为横向,注意系统没有真正的“半刀纸”,只有把上述纸张横着看才符合要求。打印时不需要设置为横打
customerReport.PrintOptions.PaperOrientation = CrystalDecisions.Shared.PaperOrientation.Landscape;
CrystalReportViewer1.HasCrystalLogo = false;
CrystalReportViewer1.HasToggleGroupTreeButton = false;
CrystalReportViewer1.HasViewList = false;
try
{
//CrystalReportViewer1.PrintMode = CrystalDecisions.Web.PrintMode.ActiveX;
System.Drawing.Printing.PrintDocument printDocument = new System.Drawing.Printing.PrintDocument();
customerReport.PrintOptions.PrinterName = printDocument.PrinterSettings.PrinterName;
customerReport.PrintToPrinter(1, true, 0, 0);
}
catch
{
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2017-02-23
展开全部
水晶报表的话不是很清楚,一般情况下用的都是finereport,控件名通常与参数结合使用,控件名即为参数名,通过控件可以获得该控件,从而获得控件值传递给对应参数,或者通过控件名获得控件后通过JS设置控件的属性。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询