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

SQL Anywhere 11.0.1 (中文) » UltraLite - .NET 编程 » UltraLite .NET 2.0 API 参考

 

ULCommandBuilder 类

将自动生成单表命令,这些命令用于使您对 System.Data.DataSet 所做的更改与关联数据库保持一致。

语法
Visual Basic
Public Class ULCommandBuilder
  Inherits DbCommandBuilder
C#
public class ULCommandBuilder: DbCommandBuilder
注释

ULDataAdapter 不会自动生成用于使您对 System.Data.DataSet 所做的更改与关联数据源保持一致的 SQL 语句。但是,如果您设置了 ULDataAdapter 的 SelectCommand 属性,则可创建一个 ULCommandBuilder 对象以自动生成 SQL 语句来实现单表更新。随后,ULCommandBuilder 会生成您未设置的任何其它 SQL 语句。

Inherits: System.ComponentModel.Component

Implements: System.IDisposable

示例

以下示例使用 ULCommand、ULDataAdapter 以及 ULConnection,从数据源中选择行。在本例中,传递了一个连接字符串、一个作为 SQL SELECT 语句的查询字符串,以及一个作为数据库表名称的字符串。该示例随后会创建一个 ULCommandBuilder。

' Visual Basic
Public Shared Function SelectULRows(ByVal connectionString As String, _
    ByVal queryString As String, ByVal tableName As String)

    Dim connection As ULConnection = New ULConnection(connectionString)
    Dim adapter As ULDataAdapter = New ULDataAdapter()

       adapter.SelectCommand = New ULCommand(queryString, connection)

       Dim builder As ULCommandBuilder = New ULCommandBuilder(adapter)

    connection.Open()

    Dim dataSet As DataSet = New DataSet()
    adapter.Fill(dataSet, tableName)

    'code to modify data in DataSet here

    'Without the ULCommandBuilder this line would fail
    adapter.Update(dataSet, tableName)

    Return dataSet

End Function

// C#
public static DataSet SelectULRows(string connectionString,
    string queryString, string tableName)
{
    using (ULConnection connection = new ULConnection(connectionString))
    {
        ULDataAdapter adapter = new ULDataAdapter();
        adapter.SelectCommand = new ULCommand(queryString, connection);
        ULCommandBuilder builder = new ULCommandBuilder(adapter);

        connection.Open();

        DataSet dataSet = new DataSet();
        adapter.Fill(dataSet, tableName);

           //code to modify data in DataSet here

        //Without the ULCommandBuilder this line would fail
        adapter.Update(dataSet, tableName);

        return dataSet;
    }
}
另请参见

ULCommandBuilder 成员
ULCommandBuilder 构造函数
DataAdapter 属性
GetDeleteCommand 方法
GetInsertCommand 方法
GetUpdateCommand 方法