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

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

SqlDataAdapter.SelectCommand プロパティ

データ ソース内のレコード選択するための Transact-SQL ステートメントまたはストアド プロシージャ取得または設定します

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

Public Property SelectCommand As
 SqlCommand
Dim instance As SqlDataAdapter
Dim value As SqlCommand

value = instance.SelectCommand

instance.SelectCommand = value
public SqlCommand SelectCommand { get; set;
 }
public:
property SqlCommand^ SelectCommand {
    SqlCommand^ get ();
    void set (SqlCommand^ 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。

解説解説

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

SelectCommand が行を返さなかった場合は、DataSetテーブル追加されず、例外生成されません。

使用例使用例

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;
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からSqlDataAdapter.SelectCommand プロパティを検索した結果を表示しています。
Weblioに収録されているすべての辞書からSqlDataAdapter.SelectCommand プロパティを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からSqlDataAdapter.SelectCommand プロパティ を検索

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

辞書ショートカット

すべての辞書の索引

「SqlDataAdapter.SelectCommand プロパティ」の関連用語

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

   

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



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

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

©2025 GRAS Group, Inc.RSS