1.20. Displaying the Data Link Properties Dialog Box
Problem
You want to display the Data Link Properties dialog box from an application so that users can create their own database connections.
Solution
Use COM interop with the OLE DB Service Component to display the Data Link Properties dialog box.
You'll need a reference to the Primary Interop Assembly (PIA) for ADO provided in the file ADODB.DLL; select adodb from the .NET tab in Visual Studio .NET's Add Reference Dialog. You'll also need a reference to the Microsoft OLE DB Service Component 1.0 Type Library from the COM tab in Visual Studio .NET's Add Reference Dialog.
The solution creates and displays a Data Link Properties dialog box using the Microsoft OLE DB Service Component through COM Interop. Follow these steps:
Create a C# Windows Forms application,
DisplayDataLinkPropertiesDialog.Add a
TextBoxcontrol. Name itconnectString. Set theMultiLineproperty =true.Add a
Buttoncontrol. Name itopenDialog.Double-click the button to add a
Clickevent handler namedopenDialog_Click.
The C# code in Form1.cs shown in the project DisplayDataLinkPropertiesDialog is shown in Example 1-19.
Example 1-19. File: Form1.cs for DisplayDataLinkPropertiesDialog solution
using System; using System.Windows.Forms; namespace DisplayDataLinkPropertiesDialog { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void openDialog_Click(object sender, EventArgs e) { ADODB.Connection adodbConnection = new ADODB.Connection( ...Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access