Crystal Report & Procedure
用存储过程作数据源创建报表 
 步骤: 
 1.编写procedure         (yearConsume) 
 2.新建dataset,这里使用步骤一创建的存储过程yearConsume 
 3.新建rpt,数据库字段从ADO.NET数据集中选取存储过程 
 4.新建aspx页面,并导入CrystalReport   Viewer 
 5.在aspx.cs页面加入代码,代码如下 
 string   strProvider   =    "Server=(local);DataBase=数据库名称;UID=用户名;PWD=密码 "; 
                         SqlConnection   myConn   =   new   SqlConnection(strProvider); 
                         myConn.Open(); 
                         SqlDataAdapter   myAdapter   =   new   SqlDataAdapter( "yearConsume ",myConn); 
                         //设置命令对象类型为存储过程 
                         myAdapter.SelectCommand.CommandType   =   CommandType.StoredProcedure; 
                         myAdapter.SelectCommand.Parameters.Add( "@rtYear ",SqlDbType.Int,4); 
                         myAdapter.SelectCommand.Parameters[ "@rtYear "].Value   =    "2006 "; 
                         DataSet   ds   =   new   DataSet(); 
                         myAdapter.Fill(ds, "tblConsumeHead "); 
                         ReportDocument   consumeReport   =   new   ReportDocument(); 
                         consumeReport.Load(Server.MapPath( "YearConsume.rpt ")); 
                         consumeReport.SetDataSource(ds); 
                         this.CrystalReportViewer1.ReportSource   =   consumeReport; 
 我在运行aspx页面的时候,出现访问报表需要登陆的页面   
 您请求的报表需要更多信息. 
 服务器名:             
 数据库名:             
 用户名:             
 密码:               
 问题出在哪里呢,请大家帮忙解决。                 
------解决方案--------------------在consumeReport.Load(Server.MapPath( "YearConsume.rpt "));后加上如下   
 	    	#region 解決登錄錯誤問題 
 			TableLogOnInfo  logonInfo  = new TableLogOnInfo(); 
 			foreach( CrystalDecisions.CrystalReports.Engine.Table tb in consumeReport.Database.Tables) 
 			{ 
 				logonInfo = tb.LogOnInfo; 
 				logonInfo.ConnectionInfo.ServerName = (local); 
 				logonInfo.ConnectionInfo.DatabaseName =  "数据库名称 ";// 
 				logonInfo.ConnectionInfo.UserID =  "用户名 "; 
 				logonInfo.ConnectionInfo.Password =  "密码 "; 
 				tb.ApplyLogOnInfo(logonInfo);  			 
 			} 
 			#endregion