OleDbDataAdapter.UpdateCommand 属性

定义

获取或设置 SQL 语句或用于在数据源中更新记录的存储过程。

public:
 property System::Data::OleDb::OleDbCommand ^ UpdateCommand { System::Data::OleDb::OleDbCommand ^ get(); void set(System::Data::OleDb::OleDbCommand ^ value); };
public System.Data.OleDb.OleDbCommand? UpdateCommand { get; set; }
[System.Data.DataSysDescription("DbDataAdapter_UpdateCommand")]
public System.Data.OleDb.OleDbCommand UpdateCommand { get; set; }
public System.Data.OleDb.OleDbCommand UpdateCommand { get; set; }
member this.UpdateCommand : System.Data.OleDb.OleDbCommand with get, set
[<System.Data.DataSysDescription("DbDataAdapter_UpdateCommand")>]
member this.UpdateCommand : System.Data.OleDb.OleDbCommand with get, set
Public Property UpdateCommand As OleDbCommand

属性值

Update(DataSet) 期间用于在对应于 DataSet 中的修改行的数据源中更新记录的 OleDbCommand

属性

示例

以下示例创建 并 OleDbDataAdapter 设置 SelectCommandUpdateCommand 属性。 它假定你已创建对象 OleDbConnection

private static OleDbDataAdapter CreateCustomerAdapter(
    OleDbConnection connection)
{
    OleDbDataAdapter dataAdapter = new OleDbDataAdapter();
    OleDbCommand command;
    OleDbParameter parameter;

    // Create the SelectCommand.
    command = new OleDbCommand("SELECT * FROM dbo.Customers " +
        "WHERE Country = ? AND City = ?", connection);

    command.Parameters.Add("Country", OleDbType.VarChar, 15);
    command.Parameters.Add("City", OleDbType.VarChar, 15);

    dataAdapter.SelectCommand = command;

    // Create the UpdateCommand.
    command = new OleDbCommand(
        "UPDATE dbo.Customers SET CustomerID = ?, CompanyName = ? " +
        "WHERE CustomerID = ?", connection);

    command.Parameters.Add(
        "CustomerID", OleDbType.Char, 5, "CustomerID");
    command.Parameters.Add(
        "CompanyName", OleDbType.VarChar, 40, "CompanyName");

    parameter = command.Parameters.Add(
        "oldCustomerID", OleDbType.Char, 5, "CustomerID");
    parameter.SourceVersion = DataRowVersion.Original;

    dataAdapter.UpdateCommand = command;

    return dataAdapter;
}
Private Function CreateCustomerAdapter( _
    ByVal connection As OleDbConnection) As OleDbDataAdapter

    Dim dataAdapter As New OleDbDataAdapter()
    Dim command As OleDbCommand
    Dim parameter As OleDbParameter

    ' Create the SelectCommand.
    command = New OleDbCommand("SELECT * FROM dbo.Customers " & _
        "WHERE Country = ? AND City = ?", connection)

    command.Parameters.Add("Country", OleDbType.VarChar, 15)
    command.Parameters.Add("City", OleDbType.VarChar, 15)

    dataAdapter.SelectCommand = command

    ' Create the UpdateCommand.
    command = New OleDbCommand("UPDATE dbo.Customers " & _
        "SET CustomerID = ?, CompanyName = ? " & _
        "WHERE CustomerID = ?", connection)

    command.Parameters.Add( _
        "CustomerID", OleDbType.Char, 5, "CustomerID")
    command.Parameters.Add( _
        "CompanyName", OleDbType.VarChar, 40, "CompanyName")

    parameter = command.Parameters.Add( _
        "oldCustomerID", OleDbType.Char, 5, "CustomerID")
    parameter.SourceVersion = DataRowVersion.Original

    dataAdapter.UpdateCommand = command

    Return dataAdapter
End Function

注解

在 期间 Update,如果未设置此属性,并且中 DataSet存在主键信息, UpdateCommand 则可以在 设置 SelectCommand 属性并使用 OleDbCommandBuilder时自动生成 。 然后,未设置的任何其他命令都由 OleDbCommandBuilder生成。 此生成逻辑要求键列信息存在于 中 DataSet。 有关详细信息,请参阅使用 CommandBuilders 生成命令

UpdateCommand 分配给之前创建的 OleDbCommand时, OleDbCommand 不会克隆 。 维护 UpdateCommand 对以前创建的 OleDbCommand 对象的引用。

注意

如果执行此命令返回行,则这些行可能会与 合并,DataSet具体取决于对象的 属性OleDbCommand的设置UpdatedRowSource方式。

适用于