DbDataAdapter.InsertCommand 속성

정의

데이터 원본에 새 레코드를 삽입하는 데 사용되는 명령을 가져오거나 설정합니다.

public:
 property System::Data::Common::DbCommand ^ InsertCommand { System::Data::Common::DbCommand ^ get(); void set(System::Data::Common::DbCommand ^ value); };
[System.ComponentModel.Browsable(false)]
public System.Data.Common.DbCommand? InsertCommand { get; set; }
[System.ComponentModel.Browsable(false)]
public System.Data.Common.DbCommand InsertCommand { get; set; }
[<System.ComponentModel.Browsable(false)>]
member this.InsertCommand : System.Data.Common.DbCommand with get, set
Public Property InsertCommand As DbCommand

속성 값

DbCommand

IDbCommand를 수행하는 동안 데이터 집합의 새 행에 대한 레코드를 데이터 소스에 삽입하는 데 사용되는 Update(DataSet)입니다.

특성

예제

다음 예제에서는 파생 클래스 OleDbDataAdapter 를 만들고 해당 속성 중 일부를 설정합니다.

public static OleDbDataAdapter CreateCustomerAdapter(
    OleDbConnection connection)
{
    OleDbDataAdapter adapter = new OleDbDataAdapter();
    OleDbCommand command;

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

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

    adapter.SelectCommand = command;

    // Create the InsertCommand.
    command = new OleDbCommand(
        "INSERT INTO Customers (CustomerID, CompanyName) " +
        "VALUES (?, ?)", connection);

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

    adapter.InsertCommand = command;
    return adapter;
}
Public Shared Function CreateCustomerAdapter( _
    connection As OleDbConnection) As OleDbDataAdapter 
  
    Dim adapter As New OleDbDataAdapter()
    Dim command As OleDbCommand

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

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

    adapter.SelectCommand = command

    ' Create the InsertCommand.
    command = New OleDbCommand( _
        "INSERT INTO Customers (CustomerID, CompanyName) " & _
        "VALUES (?, ?)", connection)

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

    adapter.InsertCommand = command
    Return adapter
End Function

설명

이 속성이 설정되지 않고 기본 키 정보가 있는 경우 Update이 속성이 DataSetInsertCommand 자동으로 생성됩니다.

적용 대상

추가 정보