1、report.datasource直接放一个dataset或datatable此种方法在代码里实现,直接为report赋数据源 特点: -无须生成xml -生成模板文件.repx中不包含表结构信息 -可用于特定表的使用,一旦将repx复制到其他地方,则无法根据repx生成表结构
2、XReport代码如下作用就是绑定一下数据XREPORT代码在设计器界面右键显示
3、public XtraReport1(DataTable dt) { InitializeComponent(); this.DataSource = dt; //这里面的Text是xrtable的属性 区分大小写
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 = "备注";
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";
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);
7、dpt.F坡纠课柩ill(dt); XtraReport1 report = new XtraReport1烫喇霰嘴(dt); report.Landscape = true; documentViewer1.DocumentSource = report; report.CreateDocument(); } catch (Exception) { throw; } }