Skip to content

DevExpress-Examples/how-to-bind-dashboard-to-sql-server-database-file

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dashboard for WinForms - How to Bind a Dashboard to a Microsoft SQL Server Database File at Runtime

This example demonstrates how to bind a Microsoft SQL Server database file (.MDF) at runtime to a dashboard created in code.

screenshot

Files to Review

Example Overview

To bind the dashboard to the Microsoft SQL Server database file, create a DashboardSqlDataSource instance and configure connection parameters.

NOTE: The MsSqlConnectionParameters object is not suitable for the SQL database file. You should use the CustomStringConnectionParameters instead.

The following connection string is used for .MDF file in this example:

XpoProvider=MSSqlServer;Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\NW19.mdf;Integrated Security=True

Database and log files NW19.mdf and NW19.ldf are not incuded in the project. They are copied to the working directory with the following post-build event command:

xcopy "$(ProjectDir)NW19*.*" $(TargetDir) /Y

The SelectQuery object is used to build a SQL query in code. You can also use the CustomSqlQuery to specify a SQL expression string.

NOTE: The SelectQueryFluentBuilder instance in not appropriate for this query because it does not support multiple JOINs.

The dashboard uses calculated fields. Create them in code and add to the DashboardSqlDataSource.CalculatedFields collection.

To bind dashboard items and calculated fields to the SQL Data Source, you should specify the Data Member setting. It is the name of the created SelectQuery.

Documentation

More Examples