Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SAP Sybase SQL Anywhere 16.0 (中文) » SQL Anywhere 服务器 - 编程 » .NET 应用程序编程 » SQL Anywhere .NET 数据提供程序

 

在 Visual Studio 项目中使用 .NET 数据提供程序

使用 SQL Anywhere .NET 数据提供程序和 Visual Studio 开发 .NET 应用程序,方法是在源代码中添加 SQL Anywhere .NET 数据提供程序的引用,以及一行引用该 SQL Anywhere .NET 数据提供程序类的语句。

前提条件

执行此任务没有前提条件。

 任务
  1. 启动 Visual Studio 并打开项目。

  2. 在 [Solution Explorer] 窗口中,右击 [References],然后单击 [Add Reference]。

    引用将指示要包含哪些提供程序并定位 SQL Anywhere .NET 数据提供程序的代码。

  3. 单击 [.NET] 选项卡,滚动列表以定位以下之一:

    • iAnywhere.Data.SQLAnywhere (.NET 2)
    • iAnywhere.Data.SQLAnywhere (.NET 3.5)
    • iAnywhere.Data.SQLAnywhere (.NET 4)
    注意

    对于 Windows Mobile 平台有单独的提供程序版本。对于 Windows Mobile SQL Anywhere .NET 数据提供程序,单击 Browse 选项卡并定位提供程序的 Windows Mobile 版本。缺省位置是 %SQLANY16%\CE\Assembly\V2

  4. 单击所需的提供程序,然后单击 [OK]。

    提供程序将添加到项目的 [Solution Explorer] 窗口的 [References] 文件夹中。

  5. 向源代码指定一条指令,以帮助使用 SQL Anywhere .NET 数据提供程序命名空间以及在其中定义的类型。

    在项目添加下面的指令行:

    • 如果使用的是 C#,请将以下行添加到源代码开始处的 using 指令列表中:

      using iAnywhere.Data.SQLAnywhere;
    • 如果使用的是 Visual Basic,则在源代码开头处添加以下行:

      Imports iAnywhere.Data.SQLAnywhere

结果

SQL Anywhere .NET 数据提供程序适用于 .NET 应用程序。

以下 C# 示例说明如何在指定了 using 指令的情况下创建连接对象:

SAConnection conn = new SAConnection();

以下 C# 示例说明如何在未指定 using 指令的情况下创建连接对象:

iAnywhere.Data.SQLAnywhere.SAConnection conn = 
    new iAnywhere.Data.SQLAnywhere.SAConnection();

以下 Visual Basic 示例说明如何在指定了 Imports 指令的情况下创建连接对象:

Dim conn As New SAConnection()

以下 Visual Basic 示例说明如何在未指定 Imports 指令的情况下创建连接对象:

Dim conn As New iAnywhere.Data.SQLAnywhere.SAConnection()

 另请参见