简体   繁体   English

如何使用Visual Studio 2012在ASP.net C#中生成水晶报表?

[英]How to generate crystal report in ASP.net C# using visual studio 2012?

I just recently installed Visual Studio 2012, everything's working good with 2010 with my Crystal report but when I migrated the code to 2012 I can't display anything. 我刚刚安装了Visual Studio 2012,在我的Crystal报表中,一切都与2010兼容,但是当我将代码迁移到2012时,我什么也无法显示。 Can you pls check if there is something I'm missing with this code: 您能否检查一下此代码是否缺少某些内容:

protected void Page_Load(object sender, EventArgs e)
        {
            SqlConnection cnn;
            string connectionString = null;
            string sql = null;
            connectionString = "data source=server; initial catalog=DBO;user id=sa; password= passw0rd";
            cnn = new SqlConnection(connectionString);
            cnn.Open();
            sql = "select BadgeNo as DataColumn1,Name as DataColumn2, Section as DataColumn3 from Safety where ID = '24'";
            SqlDataAdapter dscmd = new SqlDataAdapter(sql, cnn);
            cnn.Close();

            DataSet1 ds = new DataSet1();
            dscmd.Fill(ds, "DataTable1");

            ReportobjRpt = new Report1 ();
            objRpt.SetDataSource(ds.Tables[0]);
            CrystalReportViewer1.ReportSource = objRpt;
            CrystalReportViewer1.RefreshReport();
        }

I am using a dataset to transfer data from the SQL server to crystal report. 我正在使用数据集将数据从SQL Server传输到Crystal报表。 Please help. 请帮忙。 Thank you. 谢谢。

Try this way: 尝试这种方式:

using CrystalDecisions.CrystalReports.Engine;

public partial class Default2 : System.Web.UI.Page
{

  SqlConnection con = new SqlConnection(“Connection String “);
  protected void Page_Load(object sender, EventArgs e)
  {
    con.Open();
    ReportDocument rpt = new ReportDocument();
    rpt.Load(Server.MapPath("~/CrystalReport.rpt"));
    SqlCommand cmd = new SqlCommand("Select * from Raj_Table[tbl_name]", con);
    SqlDataAdapter da = new SqlDataAdapter();
    DataSet ds = new DataSet();
    da.SelectCommand = cmd;
    da.Fill(ds, "Raj_Table[TableName]");
    rpt.SetDataSource(ds);
    con.Close();
    CrystalReportViewer1.ReportSource = rpt;
    CrystalReportViewer1.DataBind();
  }
}

It will help you. 它会帮助你。

This code will help you: 此代码将帮助您:

protected void Page_Load(object sender, EventArgs e)
        {
            SqlConnection cnn;
            string connectionString = null;
            string sql = null;
            connectionString = "data source=server; initial catalog=DBO;user id=sa; password= passw0rd";
            cnn = new SqlConnection(connectionString);
            cnn.Open();
            SqlCommand com = new SqlCommand("select BadgeNo as DataColumn1,Name as DataColumn2, Section as DataColumn3 from Safety where ID = '24'", conn);
            adap.SelectCommand = com;
            adap.Fill(tables);
            ReportDocument doc;                
            myreport.SetDataSource(tables);
            doc = new ReportDocument();
            doc.Load(Server.MapPath("RptName.rpt"));
            myreport.ReportSource = doc;
            myreport.ReportSource = myreport;
        }

You are referencing the object objRpt instead of ReportobjRpt which is already created. 您引用的是对象objRpt而不是已创建的ReportobjRpt

Try this one: 试试这个:

protected void Page_Load(object sender, EventArgs e)  
{
    SqlConnection cnn;
    string connectionString = null;
    string sql = null;
    connectionString = "data source=server; initial catalog=DBO;user id=sa; password= passw0rd";
    cnn = new SqlConnection(connectionString);
    cnn.Open();
    sql = "select BadgeNo as DataColumn1,Name as DataColumn2, Section as DataColumn3 from Safety where ID = '24'";
    SqlDataAdapter dscmd = new SqlDataAdapter(sql, cnn);
    cnn.Close();

    DataSet1 ds = new DataSet1();
    dscmd.Fill(ds, "DataTable1");

    ReportobjRpt = new Report1 ();
    ReportobjRpt.SetDataSource(ds.Tables[0]);
    CrystalReportViewer1.ReportSource = ReportobjRpt;
    CrystalReportViewer1.RefreshReport();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Crystal Report和ASP.NET C#中使用子报表 - Using Subreport in Crystal Report and ASP.NET C# 如何在Visual Studio 2012上使用ASP.NET(包含MVC)C#配置或设置Log4Net - How to configure or setup Log4Net with ASP.NET ( included MVC) C# on Visual Studio 2012 ~ ~ 如何使用 C# Asp.net 将水晶报表直接打印到客户端机器 - How to print crystal report directly to a client machine using C# Asp.net 如何使用asp.net C#在Crystal报表中插入图像? - How to Insert Image in crystal report using asp.net C#? 如何使用 C# 在 ASP.NET MVC 中创建 Crystal Report? - How to create Crystal Report in ASP.NET MVC using C#? 如何使用带有C#/ ASP.NET的Crystal Reports生成pdf服务器端? - How to generate pdf server side using Crystal Reports with C# / ASP.NET? 在ASP.NET C#中生成报告 - Generate report in asp.net c# 如何在不询问参数字段的情况下在Asp.Net C#中的Crystal Report中加载子报表 - How to load sub report in Crystal Report in Asp.Net C# with out asking Parameter fields 在ASP.NET C#中直接打印Crystal报表 - Print Crystal Report Directly in ASP.NET C# 通过asp.net中的C#将参数传递给CRYSTAL REPORT - passing parameter to the CRYSTAL REPORT through C# in asp.net
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM