测试使用的FastReport Studio 版本为4.6.80
先引用
然后把C:/Program Files/FastReports/FastReport Studio Trial/Examples/VisualC#.NET/DataSetDemo目录下的
复制到解决方案中(切记要将这三个文件代码中的命名空间更改为自己程序的命名)
SQLServer数据库,表名demo_test 有三个字段 id(int),name(char),onemorename(char)
FastReport报表demo_test.fr3中有三个memo
[demo_test."id"] DataField属性 id
[demo_test."name"] DataField属性 name
[demo_test."onemorename"] DataField 属性 onemorename
以下是我根据DataSetDemo写的代码,在VS2005中测试通过
view plaincopy to clipboardprint?
using System;
using ;
using ;
using ;
using ;
using ;
using ;
using FastReport;
using ;
namespace FRDemoTest
{
public partial class Form1 : Form
{
TfrxReportClass report;
FrxDataTable datatable;
FrxDataSet dataset;
public Form1()
{
InitializeComponent();
}
//为FrxDataTable加载数据
private void FillTableWithSampleData(FrxDataTable datatable)
{
SqlConnection conn = new SqlConnection("server=.;database=DEMO;UID=sa;PWD=");
SqlDataAdapter da = new SqlDataAdapter("select * from demo_test", conn);
(datatable);
}
//为FrxDataSet加载数据
private void FillDataSetWithSampleData(FrxDataSet dataset)
{
SqlConnection conn = new SqlConnection("server=.;database=DEMO;UID=sa;PWD=");
SqlDataAdapter da = new SqlDataAdapter("select top 2 * from demo_test", conn);
(dataset,"demo_test");//demo_test为表名,对应FastReport模板中Memo的名字[demo_test."id"]
}
//加载FrxDataTable
private void button1_Click(object sender, EventArgs e)
{
report = new TfrxReportClass();
();//加这句可以避免重复打开报表提示错误
datatable = new FrxDataTable("demo_test");//demo_test为表名,对应FastReport模板中Memo的名字[demo_test."id"]
FillTableWithSampleData(datatable);
// = (int);
("demo_test.fr3");
//();
(true, report);
("MasterData1", report);
();
}
//加载FrxDataSet
private void button2_Click(object sender, EventArgs e)
{
report = new TfrxReportClass();
(); //加这句可以避免重复打开报表提示错误
dataset = new FrxDataSet();
FillDataSetWithSampleData(dataset);
("demo_test.fr3");
(report);
("demo_test", report, "MasterData1");
();
}
//加载Dedigner
private void button3_Click(object sender, EventArgs e)
{
report = new TfrxReportClass();
("demo_test.fr3");
();
}
}
}
using System;
using ;
using ;
using ;
using ;
using ;
using ;
using FastReport;
using ;
namespace FRDemoTest
{
public partial class Form1 : Form
{
TfrxReportClass report;
FrxDataTable datatable;
FrxDataSet dataset;
public Form1()
{
InitializeComponent();
}
//为FrxDataTable加载数据
private void FillTableWithSampleData(FrxDataTable datatable)
{
SqlConnection conn = new SqlConnection("server=.;database=DEMO;UID=sa;PWD=");
SqlDataAdapter da = new SqlDataAdapter("select * from demo_test", conn);
(datatable);
}
//为FrxDataSet加载数据
private void FillDataSetWithSampleData(FrxDataSet dataset)
{
SqlConnection conn = new SqlConnection("server=.;database=DEMO;UID=sa;PWD=");
SqlDataAdapter da = new SqlDataAdapter("select top 2 * from demo_test", conn);
(dataset,"demo_test");//demo_test为表名,对应FastReport模板中Memo的名字[demo_test."id"]
}
//加载FrxDataTable
private void button1_Click(object sender, EventArgs e)
{
report = new TfrxReportClass();
();//加这句可以避免重复打开报表提示错误
datatable = new FrxDataTable("demo_test");//demo_test为表名,对应FastReport模板中Memo的名字[demo_test."id"]
FillTableWithSampleData(datatable);
// = (int);
("demo_test.fr3");
//();
(true, report);
("MasterData1", report);
();
}
//加载FrxDataSet
private void button2_Click(object sender, EventArgs e)
{
report = new TfrxReportClass();
(); //加这句可以避免重复打开报表提示错误
dataset = new FrxDataSet();
FillDataSetWithSampleData(dataset);
("demo_test.fr3");
(report);
("demo_test", report, "MasterData1");
();
}
//加载Dedigner
private void button3_Click(object sender, EventArgs e)
{
report = new TfrxReportClass();
("demo_test.fr3");
();
}
}
}
本文来自****博客,转载请标明出处:/vwfkyy/archive/2009/10/27/