Xtrareport如何绑定dataSet数据

2025-11-01 12:40:23

1、report.datasource直接放一个dataset或datatable


此种方法在代码里实现,直接为report赋数据源
特点:
-无须生成xml
-生成模板文件.repx中不包含表结构信息
-可用于特定表的使用,一旦将repx复制到其他地方,则无法根据repx生成表结构

Xtrareport如何绑定dataSet数据

2、XReport 代码如下 作用就是绑定一下数据

XREPORT代码在设计器界面右键显示

Xtrareport如何绑定dataSet数据

3、public XtraReport1(DataTable dt)        {            InitializeComponent();            this.DataSource = dt;            //这里面的Text是xrtable的属性 区分大小写

Xtrareport如何绑定dataSet数据

4、this.xrTableCell1.DataBindings.Add("Text",dt,"bid");            this.xrTableCell2.DataBindings.Add("Text", dt, "bname");            this.xrTableCell3.DataBindings.Add("Text", dt, "shuoming");            this.xrTableCell4.Text = "编号";            this.xrTableCell5.Text = "名称";            this.xrTableCell6.Text = "备注";

Xtrareport如何绑定dataSet数据

5、private void button1_Click(object sender, EventArgs e)        {            DataTable dt = new DataTable();            string constr = "server=192.168.100.222;user=sa;pwd=p@ssw1rd;database=pwd1";

Xtrareport如何绑定dataSet数据

6、SqlConnection con = new SqlConnection(constr);            try            {                con.Open();                SqlCommand com = new SqlCommand("select bid,bname,shuoming from book",con);                SqlDataAdapter dpt = new SqlDataAdapter(com);

Xtrareport如何绑定dataSet数据

7、dpt.Fill(dt);                XtraReport1 report = new XtraReport1(dt);                report.Landscape = true;                documentViewer1.DocumentSource = report;                report.CreateDocument();            }            catch (Exception)            {                                throw;            }        }

Xtrareport如何绑定dataSet数据

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢