为什么我的DataSet数据集里的数据不能设置到rpt报表文件中(附代码)
难道这样不对?
页面上只放了一个DataGrid 和CrystalReportViewer , DataGrid1的绑定数据都可以出来,但是如何设置rpt文件的数据源呢?
我写的是web c#程序,我建立了一个DataSet1数据集,但是在建立CrystalReport1.rpt时,在project Data选项里,可以看到工程下的DataSet1数据集的名称,但其下却总是没有数据项(no items found),不知道如何才能够把DataSet里的数据集填充到rpt文件里?
myConnection=new SqlConnection("server=temp;database=temp;user id=sa;password=");
myConnection.Open();
string sqlCmd="select (select agent_pname from view_agent where iata_number=substring(a.agent,2,6)) pname,";
sqlCmd+=" agent, sum(case airline when '880' then pax when 'OTH' then 0 end ) HU_pax ,";
sqlCmd+=" sum(case airline when 'OTH' then pax when '880' then 0 end ) OTH_pax ,";
sqlCmd+=" sum(pax) total_pax,sum(case airline when '880' then sales when 'OTH' then 0 end ) HU_sales ,";
sqlCmd+=" sum(case airline when 'OTH' then sales when '880' then 0 end ) OTH_sales , sum(sales) total_sales";
sqlCmd+=" from agent_pax a where origin='HAK' and destination='PEK' and left(issue_date,6)='200209' group by agent order by total_pax desc ";
SqlCommand myCommand=new SqlCommand();
myCommand.Connection=myConnection;
myCommand.CommandType=CommandType.Text;
myCommand.CommandText=sqlCmd;
SqlDataAdapter myAd=new SqlDataAdapter();
myAd.SelectCommand=myCommand;
DataSet1 myDs=new DataSet1();
myAd.Fill(myDs,"sale_pax");
CrystalReport1 tmprpt=new CrystalReport1() ; //申明一个报表的实例 ,Report1.rpt 利用crystal report 生成
tmprpt.SetDataSource(myDs);
CrystalReportViewer1.ReportSource=tmprpt; // CrystalReportViewer 设定 source就可以咯
DataGrid1.DataSource=myDs.Tables ["sale_pax"].DefaultView ;
DataGrid1.DataBind ();
myCommand.Dispose();
myAd.Dispose();
myConnection.Close();