动态SQL存储过程如何显示在水晶报表中?
我最近写了一个存储过程,得到结果的结构大致如下 :
客户1 x月销量 x月销量 x月销量 x月销量 ...
其中x月销量前面的x月是根据用户输入的开始日期和结束日期定的,比如输入开始日期:2006.3.1,结束日期:2006.7.30,那么存储过程便有:3,4,5,6,7等5个月的销量.
存储过程运行出来是没有问题的,但我需要用水晶报表反映出来,该如何做?
------解决方案--------------------VS2005---水晶中有个数据专家的。。。存储过程像添加表一样可以添加的,然后把其中的字段拖到报表中就可以了
------解决方案--------------------我是 改了 ColumnName
// NowDT.Columns[i].ColumnName = @ "Column "+(i+1).ToString();
NowDT.TableName = @ "DataTable1 ";
CrystalReport_Total rpt = new CrystalReport_Total();
rpt.Load(dllPath + "CrystalReport_Total.rpt ");
CrystalDecisions.CrystalReports.Engine.FieldObject FieldObject;
for (int i = 0; i < NowDT.Columns.Count; i++)
{
NowDT.Columns[i].ColumnName = @ "Column "+(i+1).ToString();
}
rpt.SetDataSource(NowDT);
for (int i = 0; i < rpt.ReportDefinition.Sections[2].ReportObjects.Count; i++)
{
FieldObject = rpt.ReportDefinition.Sections[2].ReportObjects[i] as CrystalDecisions.CrystalReports.Engine.FieldObject;
}
Form rptForm = new Form();
rptForm.Text = "预览 ";
rptForm.FormBorderStyle = FormBorderStyle.FixedToolWindow;
rptForm.WindowState = System.Windows.Forms.FormWindowState.Maximized;
CrystalDecisions.Windows.Forms.CrystalReportViewer rptView = new CrystalDecisions.Windows.Forms.CrystalReportViewer();
rptView.ReportSource = rpt;
rptForm.Controls.Add(rptView);
rptView.Dock = System.Windows.Forms.DockStyle.Fill;
rptView.RefreshReport();
rptForm.Show();