OdbcDataAdapter.InsertCommand プロパティ
アセンブリ: System.Data (system.data.dll 内)

Dim instance As OdbcDataAdapter Dim value As OdbcCommand value = instance.InsertCommand instance.InsertCommand = value
/** @property */ public OdbcCommand get_InsertCommand () /** @property */ public void set_InsertCommand (OdbcCommand value)
public function get InsertCommand () : OdbcCommand public function set InsertCommand (value : OdbcCommand)
更新操作で、DataSet 内の新しい行に対応するレコードをデータ ソースに挿入するための OdbcCommand。

作成済みの OdbcCommand オブジェクトに InsertCommand プロパティが割り当てられた場合、OdbcCommand のクローンは作成されません。代わりに、InsertCommand によって、作成済みの OdbcCommand への参照が維持されます。
更新操作では、InsertCommand が設定されておらず、DataSet に主キー情報が存在する場合、OdbcCommandBuilder クラスを使用して、InsertCommand、およびデータ ソースと DataSet 間の調整に使用する追加コマンドを自動生成できます。これを行うには、OdbcDataAdapter の SelectCommand プロパティを設定する必要があります。この生成ロジックでは、DataSet 内にキー列情報が存在している必要があります。詳細については、「コマンドの自動生成」を参照してください。
![]() |
---|
このコマンドの実行によって行が返される場合、OdbcCommand オブジェクトの .Data.Odbc.OdbcCommand.UpdatedRowSource プロパティの設定によっては、返された行が DataSet に追加されることがあります。 |

OdbcDataAdapter を作成して SelectCommand プロパティと InsertCommand プロパティを設定する例を次に示します。ここでは、OdbcConnection オブジェクトが既に作成されていることを前提にしています。
Public Function CreateDataAdapter( _ ByVal connection As OdbcConnection) As OdbcDataAdapter Dim selectCommand As String = _ "SELECT CustomerID, CompanyName FROM Customers" Dim adapter As OdbcDataAdapter = _ New OdbcDataAdapter(selectCommand, connection) adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey ' Create the Insert, Update and Delete commands. adapter.InsertCommand = New OdbcCommand( _ "INSERT INTO Customers (CustomerID, CompanyName) " & _ "VALUES (?, ?)") adapter.UpdateCommand = New OdbcCommand( _ "UPDATE Customers SET CustomerID = ?, CompanyName = ? " & _ "WHERE CustomerID = ?") adapter.DeleteCommand = New OdbcCommand( _ "DELETE FROM Customers WHERE CustomerID = ?") ' Create the parameters. adapter.InsertCommand.Parameters.Add( _ "@CustomerID", OdbcType.Char, 5, "CustomerID") adapter.InsertCommand.Parameters.Add( _ "@CompanyName", OdbcType.VarChar, 40, "CompanyName") adapter.UpdateCommand.Parameters.Add( _ "@CustomerID", OdbcType.Char, 5, "CustomerID") adapter.UpdateCommand.Parameters.Add( _ "@CompanyName", OdbcType.VarChar, 40, "CompanyName") adapter.UpdateCommand.Parameters.Add( _ "@oldCustomerID", OdbcType.Char, 5, "CustomerID").SourceVersion = _ DataRowVersion.Original adapter.DeleteCommand.Parameters.Add( _ "@CustomerID", OdbcType.Char, 5, "CustomerID").SourceVersion = _ DataRowVersion.Original Return adapter End Function
public static OdbcDataAdapter CreateDataAdapter( OdbcConnection connection) { string selectCommand = "SELECT CustomerID, CompanyName FROM Customers"; OdbcDataAdapter adapter = new OdbcDataAdapter( selectCommand, connection); adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey; // Create the Insert, Update and Delete commands. adapter.InsertCommand = new OdbcCommand( "INSERT INTO Customers (CustomerID, CompanyName) " + "VALUES (?, ?)"); adapter.UpdateCommand = new OdbcCommand( "UPDATE Customers SET CustomerID = ?, CompanyName = ? " + "WHERE CustomerID = ?"); adapter.DeleteCommand = new OdbcCommand( "DELETE FROM Customers WHERE CustomerID = ?"); // Create the parameters. adapter.InsertCommand.Parameters.Add("@CustomerID", OdbcType.Char, 5, "CustomerID"); adapter.InsertCommand.Parameters.Add("@CompanyName", OdbcType.VarChar, 40, "CompanyName"); adapter.UpdateCommand.Parameters.Add("@CustomerID", OdbcType.Char, 5, "CustomerID"); adapter.UpdateCommand.Parameters.Add("@CompanyName", OdbcType.VarChar, 40, "CompanyName"); adapter.UpdateCommand.Parameters.Add("@oldCustomerID", OdbcType.Char, 5, "CustomerID").SourceVersion = DataRowVersion.Original; adapter.DeleteCommand.Parameters.Add("@CustomerID", OdbcType.Char, 5, "CustomerID").SourceVersion = DataRowVersion.Original; return adapter; }

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からOdbcDataAdapter.InsertCommand プロパティを検索する場合は、下記のリンクをクリックしてください。

- OdbcDataAdapter.InsertCommand プロパティのページへのリンク