日期:2014-05-20  浏览次数:20765 次

push模式水晶报表数据源用存储过程没有数据显示?
请问各位:问题如题,代码如下:
private   void   Page_Load(object   sender,   System.EventArgs   e)
{
SqlDataAdapter   da=new   SqlDataAdapter   ( "recordslist ",ConfigurationSettings.AppSettings[ "dsn "]);
//创建并填充DataSet
DataSet   ds=new   DataSet   ();
da.Fill   (ds, "recordslist ");
CrystalDecisions.CrystalReports.Engine.ReportDocument   myReportDocument   =       new       CrystalDecisions.CrystalReports.Engine.ReportDocument();      
myReportDocument.Load(Server.MapPath( "CrystalReport1.rpt "));               //装载rpt文件      
       
//设置rpt文件中用到的表的登录信息      
CrystalDecisions.Shared.TableLogOnInfo       loginfo=new       CrystalDecisions.Shared.TableLogOnInfo();      
loginfo.ConnectionInfo.UserID= "sa ";      
loginfo.ConnectionInfo.Password= " ";      
myReportDocument.SetDataSource(ds.Tables[ "recordslist "]);      
CrystalReportViewer.ReportSource       =       myReportDocument;      
CrystalReportViewer.DisplayGroupTree       =       false;      
CrystalReportViewer.DataBind();           //绑定显示      
                //在此处放置用户代码以初始化页面
}

------解决方案--------------------
CrystalDecisions.Shared.ConnectionInfo conn= new ConnectionInfo() ;
CrystalDecisions.CrystalReports.Engine.Table myTable;
CrystalDecisions.Shared.TableLogOnInfo myLog;
conn.ServerName = "localhost ";
conn.DatabaseName = "pubs "; //你要連的數據庫
conn.UserID = "sa ";
conn.Password = " ";
for (int i=0;i <myReportDocument.Database.Tables.Count;i++)
{
myTable=myReportDocument.Database.Tables[i];
myLog = myTable.LogOnInfo;
myLog.ConnectionInfo = conn;
myTable.ApplyLogOnInfo(myLog);
myTable.Location = myLog.TableName;
}