如何从水晶报表查看器打印数据 [英] how to print data from crystal report viewer

查看:75
本文介绍了如何从水晶报表查看器打印数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好b $ b

我想打印水晶报告中的数据。我有一个按钮打印,点击该按钮第一个报告将显示在水晶报告打印按钮上它应该打印,但它不工作,显示错误。



我附上代码。

Hi
I want to print data from crystal report. I have a button print, on clicking that button 1st report will show then on the crystal report print button it should get printed,but its not working, showing error.

I am attaching the code.

 protected void btnPrint_Click(object sender, EventArgs e)
    {
       ReportDocument cryRpt = new ReportDocument();
            cryRpt.Load("C:/Users/SUDESHNA/Documents/Visual Studio 2010/Projects/Inventory/ViewAllCrystalReport1.rpt");

            TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
            TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
            ConnectionInfo crConnectionInfo = new ConnectionInfo();
            Tables CrTables;

            crConnectionInfo.ServerName = "INSTANCE";
            crConnectionInfo.DatabaseName = "InventoryDatabase";
            crConnectionInfo.UserID = "sa";
            crConnectionInfo.Password = "gariahat";

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

            cryRpt.Refresh();
            cryRpt.PrintToPrinter(2, true, 1, 2);
    }
}





请帮助我。



Sudeshna



kindly please help me.

Sudeshna

推荐答案

请尝试使用以下代码:

Try the following code instead:
public static void SetCrystalConnection(ReportDocument doc)
{
      doc.SetDatabaseLogon("UserName", "Password");
}





如果您有不同连接的子报告,请尝试:



If you have subreports with a different connection try:

public static void SetCrystalConnection(ReportDocument doc)
{
    var defaultDbName = "TheDefaultDatabaseName";
    doc.SetDatabaseLogon("UserName", "Password");
    if (!doc.IsSubreport)
        for (int i = 0; i < doc.Subreports.Count.GetIntValue(); i++)
            if (defaultDbName != doc.Subreports[i].DataSourceConnections[0].DatabaseName)
                SetCrystalConnection(doc.Subreports[i]);
}


这篇关于如何从水晶报表查看器打印数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆