using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System.Web.UI.HtmlControls;public partial class Testreport : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        ConfigrationReports();
        
    }
    private ReportDocument NorthwindCustomersReport;    private void ConfigrationReports()
    {
        ConnectionInfo connectionInfo = new ConnectionInfo();
        connectionInfo.DatabaseName = "Northwind";
        connectionInfo.UserID = "sa";
        connectionInfo.Password = "sasa";
        SetDBLogonForReport(connectionInfo ,NorthwindCustomersReport );        NorthwindCustomersReport = new ReportDocument();
        string reportPath = Server.MapPath("NorthwindCustomers.rpt");
        NorthwindCustomersReport.Load(reportPath);
        CrystalReportViewer1.ReportSource = NorthwindCustomersReport;
    
    }
    private void SetDBLogonForReport(ConnectionInfo connectionInfo,ReportDocument reportDocument)
    {
        //using (CrystalDecisions.CrystalReports.Engine ) 
        Tables tables = reportDocument.Database.Tables;       foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables )
        {
            TableLogOnInfo tableLogonInfo = Table.LogOnInfo;
            TableLogOnInfo.ConnecitonInfo = ConnectionInfo;
            table.ApplyLogOnInfo(tableLogOnInfo);
        }
 
        
    }
   
       }如上必须包含指向 Table 类的完整命名空间路径,使其与 System.Web.UI.WebControls 命名空间的 Table 类区分开来?,怎么做,我是新手,请高手给以指点?我不会区分,具体在哪声明以区分开啊,

解决方案 »

  1.   

    错误 1 “Table”是“System.Web.UI.WebControls.Table”和“CrystalDecisions.CrystalReports.Engine.Table”之间的不明确的引用 c:\inetpub\wwwroot\costsites\Testreport.aspx.cs 48 45 http://localhost/costsites/
    这是具体 的错误信息,请高手帮忙啊,
      

  2.   

    CrystalDecisions.CrystalReports.Engine.Table tables = reportDocument.Database.Tables;
      

  3.   

    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using CrystalDecisions.CrystalReports.Engine;
    using CrystalDecisions.Shared;
    using System.Web.UI.HtmlControls;    public partial class Testreport : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                ConfigrationReports();        }
            private ReportDocument NorthwindCustomersReport;        private void ConfigrationReports()
            {
                //定义登录数据库的具体内容
                ConnectionInfo connectionInfo = new ConnectionInfo();
                connectionInfo.DatabaseName = "Northwind";
                connectionInfo.UserID = "sa";
                connectionInfo.Password = "sasa";
                //执行登录
                SetDBLogonForReport(connectionInfo, NorthwindCustomersReport);
                //绑定报表到VIEWER中
                NorthwindCustomersReport = new ReportDocument();
                string reportPath = Server.MapPath("NorthwindCustomers.rpt");
                NorthwindCustomersReport.Load(reportPath);
                CrystalReportViewer1.ReportSource = NorthwindCustomersReport;        }
            //列出登录数据库的方法
            private void  SetDBLogonForReport (ConnectionInfo connectionInfo, ReportDocument reportDocument)
            {
               Tables tables = reportDocument.Database.Tables;
                foreach (CrystalDecisions.CrystalReports.Engine.Table  table in tables)
                {
                        
                    TableLogOnInfo tableLogonInfo = table.LogOnInfo;
                    tableLogonInfo.ConnectionInfo = connectionInfo;
                    table.ApplyLogOnInfo(tableLogonInfo);
                }
                
            }
             
               }
    更改了,大小写的问题,但是还有错误:
    未将对象引用设置到对象的实例。 
    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误: 
    行 46: 
    行 47: 
    行 48:            Tables tables = reportDocument.Database.Tables;
    行 49:             foreach (CrystalDecisions.CrystalReports.Engine.Table  table in tables)
    行 50:             {
     源文件: c:\Inetpub\wwwroot\costsites\Testreport.aspx.cs    行: 48 
    请大家看看是什么问题?
    在SetDBLogonForReport方法中,从 ReportDocument 参数的 Database 属性的 Tables 属性,检索 Tables 实例。 
    注意   Tables 是包含 Table 类实例的索引类。我该怎么做才不出错误呢
      

  4.   

    朋友们,解决了,要将//执行登录
                SetDBLogonForReport(connectionInfo, NorthwindCustomersReport);
    放到绑定的下面执行就可以了,呵。多多交流