先贴出代码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.商品库存量");
}麻烦各位帮我看看,代码到底有什么问题啊,运行并不会报错,就是从表里的数据显示不出来,急啊,谢谢帮忙了,在线等回复,感激不尽!!!!!
{
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.商品库存量");
}麻烦各位帮我看看,代码到底有什么问题啊,运行并不会报错,就是从表里的数据显示不出来,急啊,谢谢帮忙了,在线等回复,感激不尽!!!!!
this.xrLabel11.DataBindings.Add("Text", ds1, "商品类别表.R1.商品名称");从未代码绑定,这里只是设计时绑定的猜测。