logo
small logo
  • Products
  • Buy
  • Support
  • About
  • Customer panel Support
    • en
    • de
    • JP
    • ZH
  • Home
  • /
  • Articles
  • /
  • Connecting to MsSQL Stored Procedures using code
  • How to connect to SQLCe

    November 11, 2019

    Microsoft SQL Server Compact Edition is a simple local relational database that doesn't require installation,

    read more
  • How to connect to VistaDB

    November 15, 2019

    The Vista database will fall into the type of embedded databases. These databases differ from

    read more
  • How to connect to the Sybase SQL Anywhere database

    February 29, 2020

    Sybase SQL Anywhere database has a number of very useful features that make it very

    read more
  • How to connect to OracleDB from FastReport .NET

    November 15, 2019

    First of all, you can use the ODBC connector. But it is fraught with a

    read more
  • How to connect the IBM DB2 database in reports designer FastReport .NET

    November 15, 2019

    To connect the report to a DB2 database, you need to connect the plugin to

    read more

Connecting to MsSQL Stored Procedures using code

November 28, 2022

We continue to develop new FastReport .NET functions. Our team is increasingly expanding the features of our library for generating reports. With a recent update, we have added the function of connecting to MsSQL stored procedures. These stored procedures are a set of instructions that are executed simultaneously. Thus, the stored procedures allow you to streamline complex operations and bring them into a single object.

Previously, you could only connect to them via a database query. Now it is enough to use the standard scheme for connecting to database tables.

List of tables and stored procedures

 

Procedure icons will be different. Also, if the procedure has input parameters, a window with its parameters will appear when it is selected. In this window, you need to set parameter values if necessary. If you use the default values, then leave the Expression and Value fields empty.

Procedure parameter editor

 

If the procedure returns output parameters, then they will appear in the “Report Parameters” after creating the connection. Such parameters will be updated only when the information is uploaded into the data source.

 

Calling the procedure from code:

// Create the MsSqlDataConnection object
var connection = new MsSqlDataConnection();
// Set the connection string
connection.ConnectionString = @"Data Source=DESKTOP-43LGTAI;AttachDbFilename=; Initial Catalog=EmployeeCaseStudy;Integrated Security=True;Persist Security Info=False;User ID=;Password=";
// Initialize all tables
connection.CreateAllTables();
// Set the connection name
connection.Name = "NewConnection";
// Create a Report Object
var report = new Report();
// Add the connection to a report
report.Dictionary.Connections.Add(connection);
// Enable connection display
connection.Enabled = true;
// Select a table and connect it to the report
foreach (TableDataSource table in connection.Tables)
{
 if (table.Name == "sp_GetUser") 
 {
 foreach (CommandParameter parameter in table.Parameters)
 if (parameter.Name == "@id")
 parameter.Value = 1;
 table.Enabled = true;
 }
}

You can find procedures in the list of tables by comparing them with ProcedureDataSource.

Now it will be faster and easier for FastReport .NET users to use pre-prepared data select scripts in several reports.

about product buy
avatar
Vladislav Yarovoy
.NET Development
Fast Reports Team: Vladislav Yarovoy - NET Development at Fast Reports
.NET FastReport Data Source

Add comment
logo
  • 800-985-8986 (English, US)
  • +4930568373928 (German)
  • +55 19 98147-8148 (Portuguese)
  • info@fast-report.com
  • 901 N Pitt Str #325 Alexandria VA 22314
  • Buy
  • Download
  • Documentation
  • Testimonials
  • How to uninstall
  • FAQ
  • Tutorial Video
  • Forum
  • Articles
  • Our News
  • Press about us
  • Resellers
  • Extended licensing
  • Contact us

© 1998-2023 by Fast Reports Inc.

  • Privacy Policy