using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
private void PrintReport(string printerName)
    {
        PageMargins margins;        //   获取   PageMargins   结构并设置   
        //报表的边距。   
        margins = Report.PrintOptions.PageMargins;
        margins.bottomMargin = 350;
        margins.leftMargin = 350;
        margins.rightMargin = 350;
        margins.topMargin = 350;
        //   应用页边距。   
        Report.PrintOptions.ApplyPageMargins(margins);        //   选择打印机。   
        Report.PrintOptions.PrinterName = "HYL1600K";        //   打印报表。将   startPageN   和   endPageN     
        //   参数设置为   0   表示打印所有页。   
        Report.PrintToPrinter(1, false, 0, 0);
    }   
出现这样的报错"当前上下文中不存在名称“Report”"

解决方案 »

  1.   

    你没有定义Report
    你的水晶报表 Report=new 你的水晶报表()
      

  2.   


    还是不行,我是这么写的
     CrystalReport1.Report = new CrystalReport1.Report();
    要提供前台代码吗?
    <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %><%@ Register assembly="CrystalDecisions.Web, Version=10.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" namespace="CrystalDecisions.Web" tagprefix="CR" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>无标题页</title>
        <style type="text/css">
            .style1
            {
                height: 44px;
            }
        </style>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        
            <table style="width:100%;">
                <tr>
                    <td class="style1" 
                        style="font-family: 宋体, Arial, Helvetica, sans-serif; font-size: x-large; text-align: center">
                        ****</td>
                </tr>
                <tr>
                    <td style="text-align: center">
                        <CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" 
                            AutoDataBind="True" Height="1068px" ReportSourceID="CrystalReportSource1" 
                            Width="904px" PrintMode="ActiveX" />
                        <CR:CrystalReportSource ID="CrystalReportSource1" runat="server">
                            <Report FileName="CrystalReport1.rpt">
                            </Report>
                        </CR:CrystalReportSource>
                    </td>
                </tr>
            </table>
        
        </div>
        </form>
    </body>
    </html>
      

  3.   

    CrystalReport1 Report = new CrystalReport1();
      

  4.   

    用了阁下的方法写,还是报错!!!找不到类型或命名空间名称“CrystalReport1”(是否缺少 using 指令或程序集引用?)
      

  5.   

    CrystalReport1 是你的报表名
    你要把这个报表添加到项目中