首页 > 编程 > .NET > 正文

asp.net 水晶报表--主从表关联问题

2024-07-10 13:06:22
字体:
来源:转载
供稿:网友

一、使用视图meeting将多表关联整合在一起

二、通过sql语句筛选数据

三、建立和主从表的关联

四、注意在crystalreport1表中插入子报表的时候,一定要将主从表的关联字段设置好,否则出乱子

主体代码如下:

/// <summary>
  /// bind crystalreport
  /// </summary>
  /// <param name="strs">sql</param>
  private void bdreport(string strs)
  {
   ocr = new crystalreport1();
   sqlconnection cnn = new sqlconnection(configurationsettings.appsettings["connectionsqlserver"]);

   sqldataadapter cmd1 = new sqldataadapter(strs,cnn);

   //create and fill the dataset.

   dataset2 ds = new dataset2();
   cmd1.fill(ds,"meeting");

   // sqldataadapter cmd2 = new sqldataadapter("select * from realplan where rplanid in (select top 10000 planid from ("+sqlstr+")as  a order by planid)", cnn);
   sqldataadapter cmd2 = new sqldataadapter(sqlisoper, cnn);
   
   cmd2.fill(ds,"realplan");

   //create the relation between the authors and titles tables.
   ds.relations.add("mo",
    ds.tables["meeting"].columns["planid"],
    ds.tables["realplan"].columns["rplanid"]);

   //binding reportviewer
   ocr.setdatasource(ds);

   this.crystalreportviewer1.reportsource = ocr;

   //close the connection.
   cnn.close();
   
  }

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表