2024年终活动

DevExpress控件使用交流,DevExpress中国社区Dev联系电话 联系电话:023-68661681

DevExpress Dashboard示例代码:连接到数据库之前自定义连接设置

来源:慧都控件网   发布时间:2014-03-13   浏览:6570次

本例演示如何在 DevExpress DashboardViewer 连接到数据库之前自定义它的连接设置,这里要用到DashboardViewer.ConfigureDataConnection事件。

>>DevExpress Dashboard下载

在本例中,仪表盘的XML定义包含了一个连接Microsoft Access数据库的路径。要想从数据库文件中看到数据,则必须提供一个连接参数,特别是用户名和密码。 Access97ConnectionParameters.UserNameFileConnectionParametersBase.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
扫码咨询
电话咨询
023-68661681
返回
顶部