当前位置:编程学习 > C#/ASP.NET >>

离奇问题求解决,关于水晶报表的!

用vs2005自带的水晶报表控件做了一个报表,在本机上调试都正常,但是用iis发布别的机子访问水晶报表页面选择参数的时候总是显示<缺少对象>。。后来发现只要在那个页面上postback就会缺少对象~!这是为什么啊~!!!!! --------------------编程问答-------------------- 没人理我啊。。。高手快出现啊。。 --------------------编程问答-------------------- 水晶报表是无状态的,每次页面刷新都要指定数据源
如果postback,则刷新时没有数据源,就提示错误 --------------------编程问答-------------------- 那为什么本机调试都好好的呢? --------------------编程问答-------------------- 页面能显示控件什么的,就是按钮啊。。下拉菜单啊。。都没用~
--------------------编程问答--------------------  ReportDocument ReportDoc=new ReportDocument();
ReportDocument 用完需要释放的,也许你没释放导致的错误
 protected void Page_Unload(object sender, EventArgs e)
 {
        ReportDoc.Close();
        ReportDoc.Dispose();
 } --------------------编程问答-------------------- 这。。。我报表都还没生成。。才在选择参数的阶段啊。。。 --------------------编程问答-------------------- using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CrystalDecisions.Shared;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Web;

public partial class Default4 : System.Web.UI.Page 
{
    //水晶报表对象
    private ReportDocument myReport;

    private void ConfigureCrystalReports()
    {   
       

        // 定义ReportDocument对象,装载Crystalreport1.rpt
        myReport = new ReportDocument();
        string reportPath = Server.MapPath("fp.rpt");
        myReport.Load(reportPath);

        
        //定义水晶报表的数据库连接信息
        ConnectionInfo connectionInfo = new ConnectionInfo();
        connectionInfo.DatabaseName = ;
        connectionInfo.UserID = ;
        connectionInfo.Password = ;
        connectionInfo.ServerName = ;
        
        //将数据库信息传递给报表
        SetDBLogonForReport(connectionInfo, myReport);
         
        //把模板对象赋给报表前端呈现控件CrystalReportViewer1
        CrystalReportViewer1.ReportSource = myReport;
    }

    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);

        }
    }
// 注意:将代码防到Page_Init或Page_Load 中
//VS2008必须放到Page_Init中
    private void Page_Init(object sender, EventArgs e)
    {
        ConfigureCrystalReports();
    }
}


--------------------编程问答-------------------- 一开始没有自动登录代码的时候也不行的。。
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,