CrystalDecisions.CrystalReports.Engine.Table.ApplyLogOnInfo对象引用未设置为对象的实例

时间:2012-08-18 11:03:51

标签: c# crystal-reports

此代码有什么问题:

ReportDocument cryrpt = new ReportDocument();
            TableLogOnInfos crtablelogoninfos = new TableLogOnInfos();
            TableLogOnInfo crtablelogoninfo = new TableLogOnInfo();
            ConnectionInfo crconnectioninfo = new ConnectionInfo();
            Tables CrTables;

            cryrpt.Load("C:\\Documents and Settings\\Administrator\\Desktop\\minfatora11-7--\\minfatora\\minfatora\\Treasury_account_out_come.rpt");

            crconnectioninfo.ServerName = "localhost";
            crconnectioninfo.DatabaseName = "MNFATOR";
            crconnectioninfo.UserID = "ICMADMIN";
            crconnectioninfo.Password = "ICMADMIN";

            CrTables = cryrpt.Database.Tables;

            foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
            {
                crtableLogoninfo = CrTable.LogOnInfo;
                crtableLogoninfo.ConnectionInfo = crConnectionInfo;
                CrTable.ApplyLogOnInfo(crtableLogoninfo);
            }





            cryrpt.RecordSelectionFormula = "select * from tblxxx where xxx=2";
            cryrpt.Refresh();
            allReportViewer.ReportSource = cryrpt;

我收到错误:“对象引用未设置为对象的实例。” 在线:

CrTable.ApplyLogOnInfo(crtableLogoninfo);

2 个答案:

答案 0 :(得分:0)

当您在此行中获得表格时,CrTablesnull

CrTables = cryrpt.Database.Tables;
  1. 您可以验证加载路径
  2. 或检查文件Treasury_account_out_come.rpt
  3. 的语法

答案 1 :(得分:-1)

cryrpt.RecordSelectionFormula = "{tblxxx.xxx}=2";