【下载FastReport.Net最新版本】
表以及与MS SQL数据源的连接的方法。 首先,在 表设计器中创建一个与MS SQL连接的 表,该 表设计器随FastReport.Net一起提供。然后,在.Net Core项目中,添加FastReport库,在Nuget包管理器中执行此操作,连接以下包:
- FastReport.Core——适用于.Net Core平台的 表生成器库;
- FastReport.Data.MsSql——连接数据库MS SQL;
- FastReport.Web——允许用户在浏览器中显示 表的Web 表对象。

转到将使用 表的控制器,在示例中,这是HomeController,必须添加对以下命名空间的引用:
using FastReport.Web;using FastReport.Data;using FastReport.Utils;
并添加代码以使用所需方法创建和加载 表,这是Index:
public IActionResult Index() { RegisteredObjects.AddConnection(typeof(MsSqlDataConnection)); WebReport webReport = new WebReport(); MsSqlDataConnection sqlConnection = new MsSqlDataConnection(); sqlConnection.ConnectionString = "Data Source = localhost; AttachDbFilename =; Initial Catalog = testdb; Integrated Security = True; Persist Security Info = False; User ID =; Password = "; sqlConnection.CreateAllTables(); webReport.Report.Dictionary.Connections.Add(sqlConnection); webReport.Report.Load($@"Reports/CoreMSSQL.frx"); ViewBag.WebReport = webReport; return View(); }
在第一行中,初始化与MsSqlDataConnection数据库的连接,然后创建一个Web 表对象,得到一个MsSqlDataConnection对象的实例,并将连接字符串设置为其中的数据库。之后给出命令——构建所有表,并添加与 表的连接,仅将 表模板加载到Web 表对象并将其传输到视图中。如果 表有变量,那么可以通过以下方式传递应用程序的值:
String value = "Products!"; webReport.Report.SetParameterValue("Param", value);
在Index.chtml视图中(取决于控制器),添加一行代码:
@await ViewBag.WebReport.Render();
显示Web Report对象。应用程序准备就绪,需要在Configure方法中向Startup.cs文件添加一行代码:
app.UseFastReport();
可以运行该应用程序并检查 表操作:

正如上图所示,从Nuget安装的连接器的使用十分方便,刚刚初始化了与数据库的连接,如果不使用MsSqlConnection,必须创建一个连接,一个DataAdapter,一个DataSet并在 表中注册数据源。
标签: 表SQLFastReportFastReport .net
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!