先贴出代码public XtraReport3()
        {
            InitializeComponent();            //连接数据源,给XtraReport3绑定数据源,包含两个数据表
            SqlConnection con = new SqlConnection("Data Source=localhost;Integrated Security=SSPI;Initial Catalog=测试所用数据库");
            SqlDataAdapter adapter;
            DataSet ds1 = new DataSet();
            con.Open();
            adapter = new SqlDataAdapter("select categoryID as 类别编号,categoryname as 类别名称,description as 类别描述 from categorybiao", con);
            adapter.Fill(ds1, "商品类别表");
            adapter = new SqlDataAdapter("select spID as 商品编号,spname as 商品名称,categoryID as 类别编号,spnumber as 商品库存量,spprice as 商品价格 from spinfobiao", con);
            adapter.Fill(ds1, "商品信息表");
            con.Close();
            this.DataSource = ds1;
            this.DataMember = "商品类别表";            this.xrLabel3.DataBindings.Add("Text", ds1, "商品类别表.类别编号");
            this.xrLabel4.DataBindings.Add("Text", ds1, "商品类别表.类别名称");
            this.xrLabel5.DataBindings.Add("Text", ds1, "商品类别表.类别描述");            //给数据集建立主外键关系
            DataColumn parentColumn = ds1.Tables["商品类别表"].Columns["类别编号"];
            DataColumn childColumn = ds1.Tables["商品信息表"].Columns["类别编号"];
            DataRelation Rl = new DataRelation("Rl", parentColumn, childColumn);
            ds1.Relations.Add(Rl);            //绑定明细表的数据源
            this.DetailReport.DataMember = "Rl";
            this.DetailReport.DataSource = ds1;            this.xrLabel11.DataBindings.Add("Text", ds1, "R1.商品名称");
            this.xrLabel12.DataBindings.Add("Text", ds1, "R1.商品价格");
            this.xrLabel13.DataBindings.Add("Text", ds1, "R1.商品库存量");
            this.xrLabel14.DataBindings.Add("Text", ds1, "R1.商品库存量");
     }麻烦各位帮我看看,代码到底有什么问题啊,运行并不会报错,就是从表里的数据显示不出来,急啊,谢谢帮忙了,在线等回复,感激不尽!!!!!

解决方案 »

  1.   

    你先测试下原始数据有没有问题,把这个ds绑定到GridControl,看看能不能正常显示主从表
      

  2.   

    我怎么觉得这里应该这样写啊:
    this.xrLabel11.DataBindings.Add("Text", ds1, "商品类别表.R1.商品名称");从未代码绑定,这里只是设计时绑定的猜测。
      

  3.   

    你好,谢谢你的回复,我有这样写,但我调用showpreview()方法时,数据也显示不出来啊?请问这是怎么回事啊?
      

  4.   

    给你一个提议,调用ShowDesignerDialog方法,会打开设计窗口,在里面查看自己代码绑定的内容是否正确(其实我都是在ShowDesignerDialog打开的设计窗口里设计好绑定内容和版面布局,之后保存一个格式报表文件,事后只要直接加载这个文件和DataSet即可)。