RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:9:30-18:00
你可能遇到了下面的问题
关闭右侧工具栏
How To Use the ODBC .NET Managed Provider in Visual C# .NET
  • 作者:xiaoxiao
  • 发表时间:2020-12-23 10:53
  • 来源:未知

适用于 This article was previously published under Q310988 For a Microsoft Visual Basic .NET version of this article, see 310985. This article refers to the following Microsoft .NET Framework Class Library namespace: Microsoft.Data.Odbc

IN THIS TASK

SUMMARY Download the ODBC .NET Managed Provider Create the Project Connection String Samples Test the Application Troubleshooting REFERENCES

SUMMARY

This step-by-step article describes how to use the ODBC .NET Managed Provider in Visual C# .NET. This article also includes samples connection strings that you can use to access your data. The ODBC .NET Data Provider is an add-on component to the Microsoft .NET Framework Software Development Kit (SDK). It provides access to native ODBC drivers the same way that the OLE DB .NET Data Provider provides access to native OLE DB Providers. Although the ODBC .NET Data Provider is intended to work with all compliant ODBC drivers, it has only been tested with the following drivers: Microsoft SQL ODBC Driver Microsoft ODBC Driver for Oracle Microsoft Jet ODBC Driver NOTE: If the .NET Framework SDK (which is included with Visual Studio .NET) is not installed, the setup for this download fails. As part of the setup for this download, the Microsoft.Data.ODBC namespace is added to the Global Assembly Cache by using the Gacutil.exe utility that is included with the .NET Framework SDK. back to the top

Download the ODBC .NET Provider

Download the ODBC .NET Managed Provider from the following Microsoft Web site:

http://msdn.microsoft.com/downloads/default.asp?URL=/downloads/sample.asp?url=/MSDN-FILES/027/001/668/msdncompositedoc.xml

The ODBC .NET Data Provider also requires that you install Microsoft Data Access Components (MDAC) version 2.7 or later. You can download the latest version of MDAC from the following Microsoft Web site:

http://msdn.microsoft.com/library/default.asp?url=/downloads/list/dataaccess.asp

After you install the ODBC .NET Data Provider, proceed to the next section to create the project. back to the top

Create the Project

Start Microsoft Visual Studio NET. Create a new Visual C# Windows Application project. Form1 is added to the project by default. From the Project menu, click Add Reference. On the .NET tab, click Microsoft.Data.ODBC.dll. After the Microsoft.Data.ODBC.dll assembly appears in the list of selected components, click OK. Switch to Code view, and add the following code immediately after the other using statements: using System.Data; using Microsoft.Data.Odbc; Add four Button controls to Form1, and label these controls SQL Server, Jet, Oracle and DSN respectively. back to the top

Connection String Samples

Add the following code to the SQL Server button: