我的ASP Web应用程序中的Crystal Report错误 [英] Error in Crystal Report in my asp web application

查看:81
本文介绍了我的ASP Web应用程序中的Crystal Report错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Crystal报表中得到了错误提示

错误 1 类型或命名空间名称 myreport'(您是否缺少使用一个程序集参考?)F:\ myaspcrystal \ Default.aspx.cs  49  错误 3 名称'  crystalReportViewer1'在当前上下文中 不存在F:\ myaspcrystal \ Default.aspx.cs  77   9  F:\ myaspcrystal \ 




 使用系统;
使用 System.Configuration;
使用 System.Data;
使用 System.Linq;
使用 System.Web;
使用 System.Web.Security;
使用 System.Web.UI;
使用 System.Web.UI.HtmlControls;
使用使用System.Web.UI.WebControls;
使用 System.Web.UI.WebControls.WebParts;
使用 System.Xml.Linq;
使用 System.Data.SqlClient;
使用 System.IO;
使用 System.Collections.Generic;
使用 CrystalDecisions.CrystalReports.Engine;
使用 CrystalDecisions.Shared; 



 公共 部分  class  _Default:System.Web.UI.Page
{
    公共 静态 字符串 connectionString = " ;

    私有 SqlDataAdapter dataAdapter;
    私有 DataSet dataSet;
    私有 DataTable dataTable;

    //  ***结束ADO.NET对象*** 
    私有 静态 字符串名称;
    私有 静态 字符串单元格;
    私有 静态 字符串地址;
    // 私有静态字符串EmpId; 
    受保护的 无效 Page_Load(对象发​​件人,EventArgs e)
    {
        字符串命令字符串= " ;

        //  sql命令和数据库连接之间的链接
        dataAdapter =  SqlDataAdapter(commandstring,connectionString);

        // 定义要使用的插入,更新和删除sql命令.
        //  BuildCommands(); 

        // 从数据库声明并填充内存中的数据集
        dataSet =  DataSet();
        dataSet.CaseSensitive =  true ;
        dataAdapter.Fill(dataSet," );


        myreport报告=  myreport(); // 错误行1 
        
        
        
             
        
        mydataset ds =  mydataset();
        mydataset.DataTable1DataTable t =(mydataset.DataTable1DataTable)ds.Tables [ 0 ];

        dataTable = dataSet.Tables [ 0 ];


         foreach (DataRow dataRow  in  dataTable.Rows中)
        {
            // 从数据行中的列值加载全局字符串
            //  CustId = dataRow ["].ToString().Trim(); 
            名称= dataRow [" ].ToString().Trim();
            Cell = dataRow [" ].ToString().Trim();
            地址= dataRow [" ].ToString().Trim();


            t.AddDataTable1Row(名称,单元格,地址);
        }



        Report.SetDataSource(ds);

        crystalReportViewer1.ReportSource =报告; // 错误第2行
 
    }
} 




嘿,
将此"myreport Report = new myreport();"替换为
ReportDocument Report = new ReportDocument();

然后将此报表"对象分配给crystalReportViewer1
如下所示:-
并确保您未使用报告查看器的类名称来绑定报告
crystalReportViewer1.ReportSource = crystalReport;


替换您的第一个错误行

ReportDocument crystalReport = new ReportDocument();


替换您的第二条错误线


CrystalReportViewer1.ReportSource = crystalReport;


i am getting the fallowing error in Crystal reports

Error	1	The type or namespace name 'myreport' could not be found (are you missing a using directive or an assembly reference?)	F:\myaspcrystal\Default.aspx.cs	49	9	F:\myaspcrystal\



Error	3	The name 'crystalReportViewer1' does not exist in the current context	F:\myaspcrystal\Default.aspx.cs	77	9	F:\myaspcrystal\




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 System.Data.SqlClient;
using System.IO;
using System.Collections.Generic;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;



public partial class _Default : System.Web.UI.Page 
{
    public static string connectionString = "Data Source=FAROOQPC\\SQLEXPRESS; Initial Catalog=mydb; Integrated Security=True";

    private SqlDataAdapter  dataAdapter;
    private DataSet dataSet;
    private DataTable dataTable;

    // *** End ADO.NET objects ***
    private static string Name;
    private static string Cell;
    private static string Address;
    //private static string EmpId;
    protected void Page_Load(object sender, EventArgs e)
    {
        string commandstring = "select * from db";

        // The link between the sql command and the database connection
        dataAdapter = new SqlDataAdapter(commandstring, connectionString);

        // Define insert, update, and delete sql commands to use.
        //    BuildCommands();

        // Declare and fill the in-memory dataset from the database
        dataSet = new DataSet();
        dataSet.CaseSensitive = true;
        dataAdapter.Fill(dataSet, "Employee");


        myreport Report = new myreport(); //error line 1
        
        
        
             
        
        mydataset ds=new mydataset();
        mydataset.DataTable1DataTable t = (mydataset.DataTable1DataTable)ds.Tables[0];

        dataTable = dataSet.Tables[0];


        foreach (DataRow dataRow in dataTable.Rows)
        {
            // Load global strings from column values in the datarow
            //CustId = dataRow[""].ToString().Trim();
            Name = dataRow["Name"].ToString().Trim();
            Cell = dataRow["Cell"].ToString().Trim();
            Address = dataRow["Address"].ToString().Trim();


            t.AddDataTable1Row(Name, Cell, Address);
        }



        Report.SetDataSource(ds);

        crystalReportViewer1.ReportSource = Report;     //Error Line 2            
 
    }
}



any one help me to figure it out

解决方案

Check the name of your CrystalReportViewer whether it is "crystalReportViewer1" or something else.


Hey,
Replace this ''myreport Report = new myreport();'' with
ReportDocument Report = new ReportDocument();

then Assign this ''Report'' object to crystalReportViewer1
As given below:-
and make sure you r not using the Class name of report viewer to bind the report
crystalReportViewer1.ReportSource = crystalReport;


REPLACE YOUR FIRST ERROR LINE BY

ReportDocument crystalReport = new ReportDocument();


REPLACE YOUR SECOND ERROR LINE BY


CrystalReportViewer1.ReportSource = crystalReport;


这篇关于我的ASP Web应用程序中的Crystal Report错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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