我已经安装了FastReport.Net来生成报告。

我提供了以下参考资料:

FastReport.dll , FastReport.Web.dll , FastReport.Bars.dll , FastReport.Editor.dll , FastReport.Service.dll


另外,我还在工具箱中创建了一个名为FastReport.Net的自定义选项卡,并将FastReport控件/组件添加到该选项卡中,而我拥有的控件是:

Pointer and WebReport


我在.aspx页面上拖放了WebReport组件,这使我的web.config像这样:

<?xml version="1.0"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="FastReport.Web, Version=2016.3.13.0, Culture=neutral, PublicKeyToken=DB7E5CE63278458C" />
        <add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        <add assembly="FastReport, Version=2016.3.13.0, Culture=neutral, PublicKeyToken=DB7E5CE63278458C" />
      </assemblies>
    </compilation>
  </system.web>
  <connectionStrings>
    <add name="ConnectionString" connectionString="Data Source=WIN-SERVER;Initial Catalog=RndDatabase;User ID=development;Password=development" providerName="System.Data.SqlClient" />
  </connectionStrings>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <handlers>
      <add name="FastReportHandler" path="FastReport.Export.axd" verb="*" type="FastReport.Web.Handlers.WebExport" />
    </handlers>
  </system.webServer>
</configuration>


我的问题是我如何能够从数据库中获取数据并使用FastReport打印报告。

我已经在项目中创建了一个dataset.xsd,但是当我在FastReport(ctrl + Shift + F10)上的设计中单击Select DataSource...时,它会打开一个弹出窗口,其中没有可供选择的选项。

还有其他程序吗?

编辑

我已经试过了:

using System;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data.SqlClient;
using System.Web.UI.WebControls;

using FastReport;
using FastReport.Web.Handlers;
using FastReport.Wizards;
using FastReport.Utils;
using FastReport.TypeConverters;
using FastReport.Code;
using FastReport.MSChart;
using FastReport.Data;
using FastReport.Design.StandardDesigner;


namespace fastreports4
{
    public partial class fastrepo : System.Web.UI.Page
    {
        string sql = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        public DataSet BindData()
        {
            DataSet _dataSet = new DataSet();
            SqlConnection con = new SqlConnection(sql);
            SqlCommand cmd = new SqlCommand("select * from cities", con);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(_dataSet);
            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();
            return _dataSet;
        }


        protected void Button1_Click(object sender, EventArgs e)
        {
            DataSet _dataSet = new DataSet();
            _dataSet = BindData();
            Report report = new Report();
            // register the "Cities" table
            report.RegisterData(_dataSet.Tables[0], "Cities");
            // enable it to use in a report
            report.GetDataSource("Cities").Enabled = true;
            // create A4 page with all margins set to 1cm
            ReportPage page1 = new ReportPage();
            page1.Name = "Page1";
            report.Pages.Add(page1);
            // create ReportTitle band
            page1.ReportTitle = new ReportTitleBand();
            page1.ReportTitle.Name = "FastReport";
            // set its height to 1.5cm
            page1.ReportTitle.Height = Units.Centimeters * 1.5f;
            // create group header
            GroupHeaderBand group1 = new GroupHeaderBand();
            group1.Name = "Cities Data";
            group1.Height = Units.Centimeters * 1;
            // set group condition
            group1.Condition = "[Cities.CityName]";//[Cities.CityName].Substring(0, 1)
            // add group to the page.Bands collection
            page1.Bands.Add(group1);
            // create group footer
            group1.GroupFooter = new GroupFooterBand();
            group1.GroupFooter.Name = "GroupFooter1";
            group1.GroupFooter.Height = Units.Centimeters * 1;
            // create DataBand
            DataBand data1 = new DataBand();
            data1.Name = "Data1";
            data1.Height = Units.Centimeters * 0.5f;
            // set data source
            data1.DataSource = report.GetDataSource("Cities");
            // connect databand to a group
            group1.Data = data1;
            // create "Text" objects
            // report title
            TextObject text1 = new TextObject();
            text1.Name = "Text1";
            // set bounds
            text1.Bounds = new System.Drawing.RectangleF(0, 0,
            Units.Centimeters * 19, Units.Centimeters * 1);
            // set text
            text1.Text = "CitiesData";
            // set appearance
            text1.HorzAlign = HorzAlign.Center;
            text1.Font = new System.Drawing.Font("Tahoma", 14, FontStyle.Bold);
            // add it to ReportTitle
            page1.ReportTitle.Objects.Add(text1);
            // group
            TextObject text2 = new TextObject();
            text2.Name = "Text2";
            text2.Bounds = new RectangleF(0, 0,
            Units.Centimeters * 2, Units.Centimeters * 1);
            text2.Text = "[Cities.CityName]";//[Cities.CityName].Substring(0, 1)
            text2.Font = new Font("Tahoma", 10, FontStyle.Bold);
            // add it to GroupHeader
            group1.Objects.Add(text2);
            report.Show();
        }
    }
}


在这里,我想通过单击按钮生成报告,当单击按钮以生成报告时,它在行report.Show();上给我一个错误,说:


  DragDrop注册失败。


当我继续执行时,它将在report.Show();处停止执行。

最佳答案

一种方法是可以使用称为WebReport的FastReport控件。

为此,您需要做的是在ToolBox步骤中为此创建一个新的自定义选项卡,如下所示:


右键单击工具箱,然后单击创建名为FastReport的新选项卡(您可以输入任何名称)
添加FastReport的dll
在此之后,拖放Webreport控件并创建报告。
如果要从菜单与数据库进行交互,请添加DataSource。


就是这样!

关于c# - 使用FastReport.Net创建报告,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38122027/

10-10 07:36