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

SQL Anywhere 11.0.1 (日本語) » Ultra Light - .NET プログラミング » Ultra Light .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 プロパティを設定すると単一テーブルを更新する SQL 文を自動的に生成するような、ULCommandBuilder オブジェクトを作成することはできます。これにより、設定していない追加の SQL 文が ULCommandBuilder によって生成されます。

継承:System.ComponentModel.Component

実装: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 メソッド