SQL Anywhere .NET 数据提供程序可与 Visual Studio 2005 或更高版本搭配使用开发应用程序。若要使用 SQL Anywhere .NET 数据提供程序,Visual Studio 项目中必须包括以下两项:
对 SQL Anywhere .NET 数据提供程序 DLL 的引用
源代码中引用 SQL Anywhere .NET 数据提供程序类的一行语句
下面详细说明这些步骤。
有关安装和注册 SQL Anywhere .NET 数据提供程序的信息,请参见部署 SQL Anywhere .NET 数据提供程序。
添加引用可通知 Visual Studio 要包含哪些 DLL 以找到 SQL Anywhere .NET 数据提供程序的代码。
启动 Visual Studio 并打开项目。
在 [Solution Explorer] 窗口中,右击 [References],然后选择 [Add Reference]。
在 [.NET] 选项卡上,单击 [Browse] 来查找 iAnywhere.Data.SQLAnywhere.dll。请注意,对于每个 Windows 和 Windows Mobile 平台,都提供单独的 DLL 版本。
对于 Windows SQL Anywhere .NET 数据提供程序,缺省位置是 install-dir\Assembly\v2。
对于 Windows Mobile SQL Anywhere .NET 数据提供程序,缺省位置是 install-dir\ce\Assembly\v2。
选择 DLL,然后单击 [Open]。
有关已安装的 DLL 的完整列表,请参见SQL Anywhere .NET 数据提供程序必需的文件。
可以验证 DLL 是否已添加到项目中。打开 [Add Reference] 窗口然后单击 [.NET] 选项卡。随即 iAnywhere.Data.SQLAnywhere.dll 出现在 [Selected Components] 列表中。单击 [OK] 关闭窗口。
DLL 将添加到项目的 [Solution Explorer] 窗口的 [References] 文件夹中。
为帮助使用 SQL Anywhere .NET 数据提供程序命名空间以及在此命名空间中定义的类型,应在源代码中添加一条指令。
启动 Visual Studio 并打开项目。
在项目添加下面的指令行:
如果使用的是 C#,请将以下行添加到项目开始处的 using
指令列表中:
using iAnywhere.Data.SQLAnywhere; |
如果使用的是 Visual Basic,则应在项目开头处 Public Class Form1
行之前添加以下行:
Imports iAnywhere.Data.SQLAnywhere |
此指令虽然不是必需的指令,但通过它可使用 SQL Anywhere .NET 类的简写形式。例如:
SAConnection conn = new SAConnection() |
在没有此指令的情况下,您仍然可以使用下面的语句:
iAnywhere.Data.SQLAnywhere.SAConnection conn = new iAnywhere.Data.SQLAnywhere.SAConnection() |
Copyright © 2009, iAnywhere Solutions, Inc. - SQL Anywhere 11.0.1 |