我按照本教程使用 C# 在 ASP.Net 中创建 RDLC 报告
在我的情况下,我想在报告向导中生成报告,就像上面的例子一样。然后生成以不同的扩展名报告。
ReportViewer1.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ReportViewer1.aspx.cs" Inherits="Project_name.Report.ReportViewer1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body style="height: 170px">
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<rsweb:reportviewer id="ReportViewer1" runat="server" width="600"></rsweb:reportviewer>
</div>
</form>
</body>
</html>
ReportViewer1.aspx.cs
using System;
using System.Configuration;
using System.Data.SqlClient;
using Microsoft.Reporting.WebForms;
using System.Data;
using Project_name.Report;
namespace Project_name.Report
{
public partial class ReportViewer1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ReportViewer1.ProcessingMode = ProcessingMode.Local;
ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/Report.rdlc");
DataSet dsCustomers = GetData("select top 20 * from AB_Products");
ReportDataSource datasource = new ReportDataSource("Project_nameDataSet", dsCustomers.Tables[0]);
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.DataSources.Add(datasource);
}
}
private DataSet GetData(string query)
{
string conString = ConfigurationManager.ConnectionStrings["Project_nameConnectionString"].ConnectionString;
SqlCommand cmd = new SqlCommand(query);
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataSet dsCustomers = new DataSet())
{
sda.Fill(dsCustomers, "DataTable1");
return dsCustomers;
}
}
}
}
}
}
在我的情况下,我在ReportViewer1.aspx.cs文件的以下行中得到红色波浪线
1. ReportViewer1.ProcessingMode = ProcessingMode.Local;
2. ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/Report.rdlc");
3. ReportViewer1.LocalReport.DataSources.Clear();
4. ReportViewer1.LocalReport.DataSources.Add(datasource);
当我将鼠标悬停在上面的线上时,它分别向我显示以下错误
1.'ReportViewer1' does not contain definition for 'ProcessingMode'
2.'ReportViewer1' does not contain definition for 'LocalReport'
3.'ReportViewer1' does not contain definition for 'LocalReport'
4.'ReportViewer1' does not contain definition for 'LocalReport'
这是我的文件夹层次结构
我该怎么做才能完成这件事。这个问题是由于错误的连接字符串而发生的吗?还是由于引用了错误的数据资源?