Active Directory のデータをDevExpress Data Grid にデータバインドする。

Active Directory 用の CData ADO.NET プロバイダーをDevExpress Windows Forms とWeb コントロールとともに使用し、Active Directory をチャートに入力します。

加藤龍彦
デジタルマーケティング

最終更新日:2022-01-31

この記事で実現できるActive Directory 連携のシナリオ

こんにちは!ウェブ担当の加藤です。マーケ関連のデータ分析や整備もやっています。

Active Directory 用の CData ADO.NET プロバイダーはサードパーティーコントロールで使うことのできる通常のADO.NET データベースアクセスコンポーネントを実装しています。データバインドするための通常のADO.NET プロセスに従うことで、UI コントロールから実データへの双方向アクセスを可能にします。 この記事では、CData を使ってDevExpress Windows Forms とウェブコントロールにデータバインドする方法を説明します。ここでは、最新のデータを表示するチャートにデータバインドします。

ActiveDirectory 接続プロパティの取得・設定方法

接続には以下の情報が必要です。

  • 有効なユーザーおよびパスワード情報 (例:Domain\BobF or cn=Bob F,ou=Employees,dc=Domain)。
  • 接続するサーバーのIP、ホスト名、ポートを含むサーバー情報。
  • BaseDN: 指定されたname にLDAP 検索の範囲を制限します。

    ちなみに、BaseDN を狭い範囲に設定することで大幅にパフォーマンスを改善できます。例えば、cn=users,dc=domain は、cn=users およびその子の範囲に戻り値の結果を制限します。

Windows Forms コントロール

下のコードでは、Active Directory でDevExpress のチャートに追加する方法を説明します。ActiveDirectoryDataAdapter はチャートコントロールのSeries プロパティにバインドします。コントロールのDiagram プロパティはx 軸とy 軸をカラム名として定義します。

using (ActiveDirectoryConnection connection = new ActiveDirectoryConnection( "User=cn=Bob F,ou=Employees,dc=Domain;Password=bob123;Server=10.0.1.2;Port=389;")) { ActiveDirectoryDataAdapter dataAdapter = new ActiveDirectoryDataAdapter( "SELECT Id, LogonCount FROM User", connection); DataTable table = new DataTable(); dataAdapter.Fill(table); DevExpress.XtraCharts.Series series = new DevExpress.XtraCharts.Series(); chartControl1.Series.Add(series); DataTable table = new DataTable(); series.ValueDataMembers.AddRange(new string[] { "LogonCount" }); series.ArgumentScaleType = DevExpress.XtraCharts.ScaleType.Qualitative; series.ArgumentDataMember = "Id"; series.ValueScaleType = DevExpress.XtraCharts.ScaleType.Numerical; chartControl1.Legend.Visibility = DevExpress.Utils.DefaultBoolean.False; ((DevExpress.XtraCharts.SideBySideBarSeriesView)series.View).ColorEach = true; } The complete code example and the resulting chart.

Web コントロール

下のコードではActive Directory でDevExpress Web を操作するための設定方法を説明します。ActiveDirectoryDataAdapter はチャートのSeries プロパティにバインドします。Diagram プロパティはx 軸とy 軸をカラム名として定義します。 using DevExpress.XtraCharts; using (ActiveDirectoryConnection connection = new ActiveDirectoryConnection( "User=cn=Bob F,ou=Employees,dc=Domain;Password=bob123;Server=10.0.1.2;Port=389;")) { ActiveDirectoryDataAdapter ActiveDirectoryDataAdapter1 = new ActiveDirectoryDataAdapter("SELECT Id, LogonCount FROM User", connection); DataTable table = new DataTable(); ActiveDirectoryDataAdapter1.Fill(table); DevExpress.XtraCharts.Series series = new Series("Series1", ViewType.Bar); WebChartControl1.Series.Add(series); DataTable table = new DataTable(); series.ValueDataMembers.AddRange(new string[] { "LogonCount" }); series.ArgumentScaleType = ScaleType.Qualitative; series.ArgumentDataMember = "Id"; series.ValueScaleType = ScaleType.Numerical; ((DevExpress.XtraCharts.SideBySideBarSeriesView)series.View).ColorEach = true; } An ASP.NET application created with the ADO.NET Provider and the DevExpress Web Forms control.(Salesforce is shown.)

関連コンテンツ

トライアル・お問い合わせ

30日間無償トライアルで、CData のリアルタイムデータ連携をフルにお試しいただけます。記事や製品についてのご質問があればお気軽にお問い合わせください。