.NODE

Listing Installed ODBC Drivers

Problem

You need a list of the ODBC drivers installed on the computer running your code.

Solution

Consult the registry.

The sample code uses the Microsoft.Win32.Registry class to display a list of all installed ODBC drivers.

The C# code is shown in Example 10-17.

Example 10-17. File: OdbcDriversForm.cs
// Namespaces, variables, and constants
using System;
using System.Text;
using Microsoft.Win32;

// . . . 

StringBuilder result = new StringBuilder( );

// Get the HKEY_LOCAL_MACHINESOFTWAREODBCODBCINST.INIODBC Drivers key.
RegistryKey keyLocalMachine =
 Registry.LocalMachine.OpenSubKey(@"SOFTWAREODBCODBCINST.INIODBC Drivers", false);
string[] valueNames = keyLocalMachine.GetValueNames( );
for(int i = 0; i < valueNames.Length; i++)
 result.Append(valueNames[i] + Environment.NewLine);

resultTextBox.Text = result.ToString( );

Discussion

The .NET Framework classes that manipulate the registry are found in the Microsoft.Win32 namespace. The registry key HKEY_LOCAL_MACHINESOFTWAREODBCODBCINST.INIODBC Drivers contains a value name for each installed ODBC driver.

Connecting to Data

Retrieving and Managing Data

Searching and Analyzing Data

Adding and Modifying Data

Copying and Transferring Data

Maintaining Database Integrity

Binding Data to .NET User Interfaces

Working with XML

Optimizing .NET Data Access

Enumerating and Maintaining Database Objects

Appendix A. Converting from C# to VB Syntax

show all menu





ADO. NET Cookbook
ADO.NET 3.5 Cookbook (Cookbooks (OReilly))
ISBN: 0596101406
EAN: 2147483647
Year: 2002
Pages: 222
Authors: Bill Hamilton
Similar book on Amazon

Flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net