本例演示如何在 DevExpress DashboardViewer 连接到数据库之前自定义它的连接设置,这里要用到DashboardViewer.ConfigureDataConnection事件。
在本例中,仪表盘的XML定义包含了一个连接Microsoft Access数据库的路径。要想从数据库文件中看到数据,则必须提供一个连接参数,特别是用户名和密码。 Access97ConnectionParameters.UserName 和 FileConnectionParametersBase.Password 两个参数用于提供用户名和密码,参考代码如下:
using System.Windows.Forms; using DevExpress.DataAccess.ConnectionParameters; namespace Dashboard_ConfigureDataConnection { public partial class Form1 : Form { public Form1() { InitializeComponent(); // Loads a dashboard from an XML file. dashboardViewer1.LoadDashboard(@"..\..\Data\nwindDashboard.xml"); } // Handles the ConfigureDataConnection event. private void dashboardViewer1_ConfigureDataConnection(object sender, DevExpress.DataAccess.ConfigureDataConnectionEventArgs e) { // Checks the name of the connection for which the event has been raised. if (e.ConnectionName == "nwindConnection") { // Gets the connection parameters used to establish a connection to the database. Access97ConnectionParameters parameters = (Access97ConnectionParameters)e.ConnectionParameters; // Specifies the user name used to access the database file. parameters.UserName = "Admin"; // Specifies the password used to access the database file. parameters.Password = "password"; } } } }
本站文章除注明转载外,均为本站原创或翻译
欢迎任何形式的转载,但请务必注明出处,尊重他人劳动成果
转载请注明:文章转载自:DevExpress控件中文网 [https://www.devexpresscn.com/]
本文地址:https://www.devexpresscn.com/post/509.html
欢迎任何形式的转载,但请务必注明出处,尊重他人劳动成果
转载请注明:文章转载自:DevExpress控件中文网 [https://www.devexpresscn.com/]
本文地址:https://www.devexpresscn.com/post/509.html