SqlCeDataAdapter.UpdateCommand プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > SqlCeDataAdapter.UpdateCommand プロパティの意味・解説 

SqlCeDataAdapter.UpdateCommand プロパティ

データ ソース内のレコード更新する SQL ステートメント取得または設定します

名前空間: System.Data.SqlServerCe
アセンブリ: System.Data.SqlServerCe (system.data.sqlserverce.dll 内)
構文構文

Public Property UpdateCommand As
 SqlCeCommand
Dim instance As SqlCeDataAdapter
Dim value As SqlCeCommand

value = instance.UpdateCommand

instance.UpdateCommand = value
public SqlCeCommand UpdateCommand { get; set;
 }
public:
property SqlCeCommand^ UpdateCommand {
    SqlCeCommand^ get ();
    void set (SqlCeCommand^ value);
}
/** @property */
public SqlCeCommand get_UpdateCommand ()

/** @property */
public void set_UpdateCommand (SqlCeCommand
 value)
public function get UpdateCommand
 () : SqlCeCommand

public function set UpdateCommand
 (value : SqlCeCommand)

プロパティ
Update 処理中にDataSet 内の変更行に対応するデータ ソース内のレコード更新するための SqlCeCommand。

解説解説

Update の処理中に、このプロパティ設定されておらず、DataSet主キー情報存在する場合UpdateCommand自動的に生成されます。このプロパティ自動的に生成されるようにするには、SelectCommand プロパティ設定し、SqlCeCommandBuilder を使用します続いて設定していない追加コマンドが、SqlCeCommandBuilder によって生成されます。この生成ロジックでは、DataSet 内にキー情報存在している必要があります

作成済みSqlCeCommandUpdateCommand割り当てられ場合SqlCeCommandクローン作成されません。UpdateCommand によって、作成済みSqlCeCommand オブジェクトへの参照維持されます。

メモメモ

このコマンド実行によって行が返される場合SqlCeCommand オブジェクトの UpdatedRowSource プロパティ設定によっては、返された行DataSetマージされることがあります

使用例使用例

SqlCeDataAdapter を作成しデータセット変更した後でUpdate メソッド呼び出してデータ ソース更新する例を次に示します

Dim cmd As SqlCeCommand = Nothing
Dim adp As SqlCeDataAdapter = Nothing

Try
    adp = New SqlCeDataAdapter()
    Dim conn As New SqlCeConnection("Data
 Source = MyDatabase.sdf")

    ' Create the SelectCommand
    '
    cmd = conn.CreateCommand()
    cmd.CommandText = "SELECT [Employee ID], [First Name], [Last
 Name] FROM Employees"
    adp.SelectCommand = cmd

    ' Create the InsertCommand
    '
    cmd = conn.CreateCommand()
    cmd.CommandText = "INSERT INTO Employees ([First Name],[Last
 Name]) VALUES (@first, @last)"

    Dim p As SqlCeParameter = Nothing

    p = cmd.Parameters.Add("@first", SqlDbType.NVarChar,
 10, "First Name")
    p.SourceVersion = DataRowVersion.Original

    p = cmd.Parameters.Add("@last", SqlDbType.NVarChar,
 20, "Last Name")
    p.SourceVersion = DataRowVersion.Original

    adp.InsertCommand = cmd

    ' Create the UpdateCommand
    '
    cmd = conn.CreateCommand()
    cmd.CommandText = "UPDATE Employees SET [First Name] = @first,
 " + _
        "[Last Name] = @last WHERE [Employee ID] = @employeeID"

    p = cmd.Parameters.Add("@first", SqlDbType.NVarChar,
 10, "First Name")
    p.SourceVersion = DataRowVersion.Current

    p = cmd.Parameters.Add("@last", SqlDbType.NVarChar,
 20, "Last Name")
    p.SourceVersion = DataRowVersion.Current

    p = cmd.Parameters.Add("@employeeID", SqlDbType.NVarChar,
 20, "Employee ID")
    p.SourceVersion = DataRowVersion.Original

    adp.UpdateCommand = cmd

    ' Populate the dataset with the results from the SELECT statement
    '
    Dim ds As New DataSet()
    adp.Fill(ds)

    ' Modify the dataset
    '
    MessageBox.Show("Number of rows: " & ds.Tables(0).Rows.Count)

    ' Insert some rows
    '
    ds.Tables(0).Rows.Add(New Object() {Nothing,
 "Nancy", "Smith"})
    ds.Tables(0).Rows.Add(New Object() {Nothing,
 "Joe", "Clayton"})

    ' Update some rows
    '
    ds.Tables(0).Rows(1)(1) = "David"
    ds.Tables(0).Rows(1)(2) = "Johnson"

    ' This will execute two INSERT and one UPDATE statements
    '
    adp.Update(ds.Tables(0))
Catch e As Exception
    MessageBox.Show(e.Message)
Finally
    If Not Nothing Is
 adp.SelectCommand Then
        adp.SelectCommand.Dispose()
    End If
    If Not Nothing Is
 adp.InsertCommand Then
        adp.InsertCommand.Dispose()
    End If
End Try
SqlCeCommand cmd = null;
SqlCeDataAdapter adp = null;

try
{
    adp = new SqlCeDataAdapter();
    SqlCeConnection conn = new SqlCeConnection("Data Source
 = MyDatabase.sdf");

    // Create the SelectCommand
    //
    cmd = conn.CreateCommand();
    cmd.CommandText = "SELECT [Employee ID], [First Name], [Last Name] FROM
 Employees";
    adp.SelectCommand = cmd;

    // Create the InsertCommand
    //
    cmd = conn.CreateCommand();
    cmd.CommandText = "INSERT INTO Employees ([First Name],[Last Name]) VALUES
 (@first, @last)";

    SqlCeParameter p = null;

    p = cmd.Parameters.Add("@first", SqlDbType.NVarChar, 10, "First
 Name");
    p.SourceVersion = DataRowVersion.Original;

    p = cmd.Parameters.Add("@last", SqlDbType.NVarChar, 20, "Last
 Name");
    p.SourceVersion = DataRowVersion.Original;

    adp.InsertCommand = cmd;

    // Create the UpdateCommand
    //
    cmd = conn.CreateCommand();
    cmd.CommandText = "UPDATE Employees SET [First Name] = @first, " +
        "[Last Name] = @last WHERE [Employee ID] = @employeeID";

    p = cmd.Parameters.Add("@first", SqlDbType.NVarChar, 10, "First
 Name");
    p.SourceVersion = DataRowVersion.Current;

    p = cmd.Parameters.Add("@last", SqlDbType.NVarChar, 20, "Last
 Name");
    p.SourceVersion = DataRowVersion.Current;

    p = cmd.Parameters.Add("@employeeID", SqlDbType.NVarChar, 20, "Employee
 ID");
    p.SourceVersion = DataRowVersion.Original;

    adp.UpdateCommand = cmd;

    // Populate the dataset with the results from the SELECT statement
    //
    DataSet ds = new DataSet();
    adp.Fill(ds);

    // Modify the dataset
    //
    MessageBox.Show("Number of rows: " + ds.Tables[0].Rows.Count);

    // Insert some rows
    //
    ds.Tables[0].Rows.Add(new object[] { null,
 "Nancy", "Smith" });
    ds.Tables[0].Rows.Add(new object[] { null,
 "Joe", "Clayton" });

    // Update some rows
    //
    ds.Tables[0].Rows[1][1] = "David";
    ds.Tables[0].Rows[1][2] = "Johnson";

    // This will execute two INSERT and one UPDATE statements 
    //
    adp.Update(ds.Tables[0]);

    
}
catch (Exception e)
{
    MessageBox.Show(e.Message);
}
finally
{
    if (null != adp.SelectCommand) adp.SelectCommand.Dispose();
    if (null != adp.InsertCommand) adp.InsertCommand.Dispose();
}
.NET Framework のセキュリティ.NET Frameworkセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
SqlCeDataAdapter クラス
SqlCeDataAdapter メンバ
System.Data.SqlServerCe 名前空間
DeleteCommand
InsertCommand
SelectCommand



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

SqlCeDataAdapter.UpdateCommand プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



SqlCeDataAdapter.UpdateCommand プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS