使用未绑定字段的动态报表,出错。

tdsoft tdsoft 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
测试程序如下:(参考CrystalReport官方网站上的VB版未绑定字段的动态报表)
Visual C#的Windows应用程序,数据库为SQL Server2000
一个报表名为CrystalReport1,里面包含两个未绑定字段:“未绑定字符串1”和“未绑定字符串2”
一个窗口上面一个名为CrystalReportViewer1的报表控件,一个按钮。要实现单击按钮后“未绑定字符串1”显示数据库mcms里表TBCUSTOM的ID字段内容,“未绑定字符串2”显示NAME字段。
单击事件如下:

private void button1_Click(object sender, System.EventArgs e)
{
string myConnectionString = "workstation id=YINMIAO;packet size=4096;user id=sa;data source=huijie;persist security info=False;initial catalog=mcms;password=111111";
SqlConnection myConnection = new SqlConnection(myConnectionString);
string mySelectQuery = "select ID,NAME from TBCUSTOM";
SqlDataAdapter myDataAdapter = new SqlDataAdapter(mySelectQuery,myConnection);

DataSet ds = new DataSet();

myDataAdapter.Fill(ds,"TBCUSTOM");

string strReport =@"G:\WindowsApplication10\CrystalReport1.rpt";
ReportDocument report = new ReportDocument();

FormulaFieldDefinition crFormulaTextField1;
FormulaFieldDefinition crFormulaTextField2;
FormulaFieldDefinitions crFormulas;

report.Load(strReport);
report.Refresh();
report.SetDataSource(ds);

crFormulas = report.DataDefinition.FormulaFields;
crFormulaTextField1 = crFormulas[0];
crFormulaTextField2 = crFormulas[1];
crFormulaTextField1.Text="{TBCUSTOM.ID}";
crFormulaTextField2.Text="{TBCUSTOM.NAME}";

this.CrystalReportViewer1.ReportSource = report;
}

结果并未显示任何数据。
测试在窗口上放一个dataGrid控件dataGrid1,设dataGrid1.DataSource=ds,可在dataGrid1里看到正确数据,证明数据已经Fill进了ds。
不知为何在报表中无法显示select出的数据
...全文

相关推荐

评论 19
收藏 已收藏
分享
返回顶部
tdsoft
C# 111,129 成员 642,540 内容