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

Dim instance As SqlDataAdapter Dim value As SqlCommand value = instance.SelectCommand instance.SelectCommand = value
/** @property */ public SqlCommand get_SelectCommand () /** @property */ public void set_SelectCommand (SqlCommand value)
public function get SelectCommand () : SqlCommand public function set SelectCommand (value : SqlCommand)
Fill 処理中に、DataSet に格納するレコードをデータベースから選択するための SqlCommand。

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

SqlDataAdapter を作成し、SelectCommand、InsertCommand、UpdateCommand、および DeleteCommand の各プロパティを設定する例を次に示します。ここでは、SqlConnection オブジェクトが既に作成されていることを前提にしています。
Public Function CreateCustomerAdapter( _ ByVal connection As SqlConnection) As SqlDataAdapter Dim adapter As SqlDataAdapter = New SqlDataAdapter() ' Create the SelectCommand. Dim command As SqlCommand = New SqlCommand( _ "SELECT * FROM Customers " & _ "WHERE Country = @Country AND City = @City", connection) ' Add the parameters for the SelectCommand. command.Parameters.Add("@Country", SqlDbType.NVarChar, 15) command.Parameters.Add("@City", SqlDbType.NVarChar, 15) adapter.SelectCommand = command ' Create the InsertCommand. command = New SqlCommand( _ "INSERT INTO Customers (CustomerID, CompanyName) " & _ "VALUES (@CustomerID, @CompanyName)", connection) ' Add the parameters for the InsertCommand. command.Parameters.Add("@CustomerID", SqlDbType.NChar, 5, "CustomerID") command.Parameters.Add("@CompanyName", SqlDbType.NVarChar, 40, "CompanyName") adapter.InsertCommand = command ' Create the UpdateCommand. command = New SqlCommand( _ "UPDATE Customers SET CustomerID = @CustomerID, CompanyName = @CompanyName " & _ "WHERE CustomerID = @oldCustomerID", connection) ' Add the parameters for the UpdateCommand. command.Parameters.Add("@CustomerID", SqlDbType.NChar, 5, "CustomerID") command.Parameters.Add("@CompanyName", SqlDbType.NVarChar, 40, "CompanyName") Dim parameter As SqlParameter = command.Parameters.Add( _ "@oldCustomerID", SqlDbType.NChar, 5, "CustomerID") parameter.SourceVersion = DataRowVersion.Original adapter.UpdateCommand = command ' Create the DeleteCommand. command = New SqlCommand( _ "DELETE FROM Customers WHERE CustomerID = @CustomerID", connection) ' Add the parameters for the DeleteCommand. command.Parameters.Add( _ "@CustomerID", SqlDbType.NChar, 5, "CustomerID") parameter.SourceVersion = DataRowVersion.Original adapter.DeleteCommand = command Return adapter End Function
public static SqlDataAdapter CreateCustomerAdapter( SqlConnection connection) { SqlDataAdapter adapter = new SqlDataAdapter(); // Create the SelectCommand. SqlCommand command = new SqlCommand("SELECT * FROM Customers " + "WHERE Country = @Country AND City = @City", connection); // Add the parameters for the SelectCommand. command.Parameters.Add("@Country", SqlDbType.NVarChar, 15); command.Parameters.Add("@City", SqlDbType.NVarChar, 15); adapter.SelectCommand = command; // Create the InsertCommand. command = new SqlCommand( "INSERT INTO Customers (CustomerID, CompanyName) " + "VALUES (@CustomerID, @CompanyName)", connection); // Add the parameters for the InsertCommand. command.Parameters.Add("@CustomerID", SqlDbType.NChar, 5, "CustomerID"); command.Parameters.Add("@CompanyName", SqlDbType.NVarChar, 40, "CompanyName"); adapter.InsertCommand = command; // Create the UpdateCommand. command = new SqlCommand( "UPDATE Customers SET CustomerID = @CustomerID, CompanyName = @CompanyName " + "WHERE CustomerID = @oldCustomerID", connection); // Add the parameters for the UpdateCommand. command.Parameters.Add("@CustomerID", SqlDbType.NChar, 5, "CustomerID"); command.Parameters.Add("@CompanyName", SqlDbType.NVarChar, 40, "CompanyName"); SqlParameter parameter = command.Parameters.Add( "@oldCustomerID", SqlDbType.NChar, 5, "CustomerID"); parameter.SourceVersion = DataRowVersion.Original; adapter.UpdateCommand = command; // Create the DeleteCommand. command = new SqlCommand( "DELETE FROM Customers WHERE CustomerID = @CustomerID", connection); // Add the parameters for the DeleteCommand. parameter = command.Parameters.Add( "@CustomerID", SqlDbType.NChar, 5, "CustomerID"); parameter.SourceVersion = DataRowVersion.Original; adapter.DeleteCommand = command; return adapter; }

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


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

- SqlDataAdapter.SelectCommand プロパティのページへのリンク