为什么我的DataSet数据集里的数据不能设置到rpt报表文件中(附代码)

brilliant123 2002-11-18 02:48:50
难道这样不对?
页面上只放了一个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();
...全文
77 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
anna_aiya 2002-11-19
  • 打赏
  • 举报
回复
其实我也不知道.net是怎么回事,我在服务资源管理器建立了连接之后,把表拖到数据集里,再把.net工程退出去重新启动一下,这才能在rpt文件里找到数据集里的数据了
anna_aiya 2002-11-18
  • 打赏
  • 举报
回复
up

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧