一、使用视图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();
}
新闻热点
疑难解答
图片精选