SqlDataAdapter コンストラクタとは? わかりやすく解説

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

SqlDataAdapter コンストラクタ (SqlCommand)

SelectCommand プロパティとして SqlCommand指定してSqlDataAdapter クラス新しインスタンス初期化します。

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

Public Sub New ( _
    selectCommand As SqlCommand _
)
Dim selectCommand As SqlCommand

Dim instance As New SqlDataAdapter(selectCommand)
public SqlDataAdapter (
    SqlCommand selectCommand
)
public:
SqlDataAdapter (
    SqlCommand^ selectCommand
)
public SqlDataAdapter (
    SqlCommand selectCommand
)
public function SqlDataAdapter (
    selectCommand : SqlCommand
)

パラメータ

selectCommand

Transact-SQL SELECT ステートメントまたはストアド プロシージャである SqlCommand。SqlDataAdapter の SelectCommand プロパティとして設定されます。

解説解説

SqlDataAdapter コンストラクタ実装により、SelectCommand プロパティselectCommand パラメータ指定した値に設定します

SqlDataAdapterインスタンス作成すると、次のように各読み書き可能プロパティ初期値設定されます。

プロパティ

初期値

MissingMappingAction

MissingMappingAction.Passthrough

MissingSchemaAction

MissingSchemaAction.Add

これらのプロパティの値は、各プロパティ個別呼び出して変更できます

作成済みSqlCommandSelectCommand またはその他のいずれかコマンド プロパティ割り当てられ場合SqlCommandクローン作成されません。SelectCommand によって、作成済みSqlCommand オブジェクトへの参照維持されます。

使用例使用例

SqlDataAdapter作成し、そのプロパティ一部設定する例を次に示します

Public Function CreateSqlDataAdapter(ByVal
 selectCommand As SqlCommand, _
    ByVal connection As SqlConnection) As
 SqlDataAdapter

    Dim adapter As SqlDataAdapter = New
 SqlDataAdapter(selectCommand)
    adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey

    ' Create the commands.
    adapter.InsertCommand = New SqlCommand( _
        "INSERT INTO Customers (CustomerID, CompanyName) "
 & _
         "VALUES (@CustomerID, @CompanyName)", connection)

    adapter.UpdateCommand = New SqlCommand( _
        "UPDATE Customers SET CustomerID = @CustomerID, CompanyName
 = @CompanyName " & _
        "WHERE CustomerID = @oldCustomerID", connection)

    adapter.DeleteCommand = New SqlCommand( _
        "DELETE FROM Customers WHERE CustomerID = @CustomerID",
 connection)

    ' Create the parameters.
    adapter.InsertCommand.Parameters.Add("@CustomerID",
 _
        SqlDbType.Char, 5, "CustomerID")
    adapter.InsertCommand.Parameters.Add("@CompanyName",
 _
        SqlDbType.VarChar, 40, "CompanyName")

    adapter.UpdateCommand.Parameters.Add("@CustomerID",
 _
        SqlDbType.Char, 5, "CustomerID")
    adapter.UpdateCommand.Parameters.Add("@CompanyName",
 _
        SqlDbType.VarChar, 40, "CompanyName")
    adapter.UpdateCommand.Parameters.Add("@oldCustomerID",
 _
        SqlDbType.Char, 5, "CustomerID").SourceVersion = DataRowVersion.Original

    adapter.DeleteCommand.Parameters.Add("@CustomerID",
 _
        SqlDbType.Char, 5, "CustomerID").SourceVersion = DataRowVersion.Original

    Return adapter
End Function
public static SqlDataAdapter CreateSqlDataAdapter(SqlCommand
 selectCommand,
    SqlConnection connection)
{
    SqlDataAdapter adapter = new SqlDataAdapter(selectCommand);
    adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;

    // Create the other commands.
    adapter.InsertCommand = new SqlCommand(
        "INSERT INTO Customers (CustomerID, CompanyName) " +
        "VALUES (@CustomerID, @CompanyName)", connection);

    adapter.UpdateCommand = new SqlCommand(
        "UPDATE Customers SET CustomerID = @CustomerID, CompanyName = @CompanyName
 " +
        "WHERE CustomerID = @oldCustomerID", connection);

    adapter.DeleteCommand = new SqlCommand(
        "DELETE FROM Customers WHERE CustomerID = @CustomerID", connection);

    // Create the parameters.
    adapter.InsertCommand.Parameters.Add("@CustomerID", 
        SqlDbType.Char, 5, "CustomerID");
    adapter.InsertCommand.Parameters.Add("@CompanyName", 
        SqlDbType.VarChar, 40, "CompanyName");

    adapter.UpdateCommand.Parameters.Add("@CustomerID", 
        SqlDbType.Char, 5, "CustomerID");
    adapter.UpdateCommand.Parameters.Add("@CompanyName", 
        SqlDbType.VarChar, 40, "CompanyName");
    adapter.UpdateCommand.Parameters.Add("@oldCustomerID", 
        SqlDbType.Char, 5, "CustomerID").SourceVersion = DataRowVersion.Original;

    adapter.DeleteCommand.Parameters.Add("@CustomerID", 
        SqlDbType.Char, 5, "CustomerID").SourceVersion = DataRowVersion.Original;

    return adapter;
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

SqlDataAdapter コンストラクタ (String, SqlConnection)

SelectCommand オブジェクトSqlConnection オブジェクト指定してSqlDataAdapter クラス新しインスタンス初期化します。

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

Public Sub New ( _
    selectCommandText As String, _
    selectConnection As SqlConnection _
)
Dim selectCommandText As String
Dim selectConnection As SqlConnection

Dim instance As New SqlDataAdapter(selectCommandText,
 selectConnection)
public SqlDataAdapter (
    string selectCommandText,
    SqlConnection selectConnection
)
public:
SqlDataAdapter (
    String^ selectCommandText, 
    SqlConnection^ selectConnection
)
public SqlDataAdapter (
    String selectCommandText, 
    SqlConnection selectConnection
)
public function SqlDataAdapter (
    selectCommandText : String, 
    selectConnection : SqlConnection
)

パラメータ

selectCommandText

Transact-SQL SELECT ステートメントまたはストアド プロシージャである String。SqlDataAdapter の SelectCommand プロパティによって使用されます。

selectConnection

接続を表す SqlConnection。

解説解説

SqlDataAdapter実装では、SqlConnection開いてない場合は、接続開かれ、再び閉じられます。これは、アプリケーション複数SqlDataAdapter オブジェクトFill メソッド呼び出す必要がある場合効果的です。SqlConnection が既に開いている場合、その接続閉じるには、明示的に Close または Dispose呼び出す必要があります

SqlDataAdapterインスタンス作成すると、次のように各読み書き可能プロパティ初期値設定されます。

プロパティ

初期値

MissingMappingAction

MissingMappingAction.Passthrough

MissingSchemaAction

MissingSchemaAction.Add

これらのプロパティの値は、各プロパティ個別呼び出して変更できます

使用例使用例

SqlDataAdapter作成し、そのプロパティ一部設定する例を次に示します

Public Function CreateSqlDataAdapter(ByVal
 commandText As String, _
    ByVal connection As SqlConnection) As
 SqlDataAdapter

    Dim adapter As SqlDataAdapter = New
 SqlDataAdapter(commandText, connection)

    adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey

    ' Create the commands.
    adapter.InsertCommand = New SqlCommand( _
        "INSERT INTO Customers (CustomerID, CompanyName) "
 & _
         "VALUES (@CustomerID, @CompanyName)")

    adapter.UpdateCommand = New SqlCommand( _
        "UPDATE Customers SET CustomerID = @CustomerID, CompanyName
 = @CompanyName " & _
        "WHERE CustomerID = @oldCustomerID")

    adapter.DeleteCommand = New SqlCommand( _
        "DELETE FROM Customers WHERE CustomerID = @CustomerID")

    ' Create the parameters.
    adapter.InsertCommand.Parameters.Add("@CustomerID",
 _
        SqlDbType.Char, 5, "CustomerID")
    adapter.InsertCommand.Parameters.Add("@CompanyName",
 _
        SqlDbType.VarChar, 40, "CompanyName")

    adapter.UpdateCommand.Parameters.Add("@CustomerID",
 _
        SqlDbType.Char, 5, "CustomerID")
    adapter.UpdateCommand.Parameters.Add("@CompanyName",
 _
        SqlDbType.VarChar, 40, "CompanyName")
    adapter.UpdateCommand.Parameters.Add("@oldCustomerID",
 _
        SqlDbType.Char, 5, "CustomerID").SourceVersion = DataRowVersion.Original

    adapter.DeleteCommand.Parameters.Add("@CustomerID",
 _
        SqlDbType.Char, 5, "CustomerID").SourceVersion = DataRowVersion.Original

    Return adapter
End Function
public static SqlDataAdapter CreateSqlDataAdapter(string
 commandText,
    SqlConnection connection)
{
    SqlDataAdapter adapter = new SqlDataAdapter(commandText, connection);

    adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;

    // Create the other commands.
    adapter.InsertCommand = new SqlCommand(
        "INSERT INTO Customers (CustomerID, CompanyName) " +
        "VALUES (@CustomerID, @CompanyName)");

    adapter.UpdateCommand = new SqlCommand(
        "UPDATE Customers SET CustomerID = @CustomerID, CompanyName = @CompanyName
 " +
        "WHERE CustomerID = @oldCustomerID");

    adapter.DeleteCommand = new SqlCommand(
        "DELETE FROM Customers WHERE CustomerID = @CustomerID");

    // Create the parameters.
    adapter.InsertCommand.Parameters.Add("@CustomerID", 
        SqlDbType.Char, 5, "CustomerID");
    adapter.InsertCommand.Parameters.Add("@CompanyName", 
        SqlDbType.VarChar, 40, "CompanyName");

    adapter.UpdateCommand.Parameters.Add("@CustomerID", 
        SqlDbType.Char, 5, "CustomerID");
    adapter.UpdateCommand.Parameters.Add("@CompanyName", 
        SqlDbType.VarChar, 40, "CompanyName");
    adapter.UpdateCommand.Parameters.Add("@oldCustomerID", 
        SqlDbType.Char, 5, "CustomerID").SourceVersion = DataRowVersion.Original;

    adapter.DeleteCommand.Parameters.Add("@CustomerID", 
        SqlDbType.Char, 5, "CustomerID").SourceVersion = DataRowVersion.Original;

    return adapter;
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

SqlDataAdapter コンストラクタ

SqlDataAdapter クラス新しインスタンス初期化します。
オーバーロードの一覧オーバーロードの一覧

名前 説明
SqlDataAdapter () SqlDataAdapter クラス新しインスタンス初期化します。

.NET Compact Framework によってサポートされています。

SqlDataAdapter (SqlCommand) SelectCommand プロパティとして SqlCommand を指定してSqlDataAdapter クラス新しインスタンス初期化します。

.NET Compact Framework によってサポートされています。

SqlDataAdapter (String, SqlConnection) SelectCommand オブジェクトと SqlConnection オブジェクト指定してSqlDataAdapter クラス新しインスタンス初期化します。

.NET Compact Framework によってサポートされています。

SqlDataAdapter (String, String) SelectCommand接続文字列指定してSqlDataAdapter クラス新しインスタンス初期化します。

.NET Compact Framework によってサポートされています。

参照参照

関連項目

SqlDataAdapter クラス
SqlDataAdapter メンバ
System.Data.SqlClient 名前空間

その他の技術情報

ADO.NET でのデータ変更
.NET Framework Data Provider for SQL Server使用

SqlDataAdapter コンストラクタ (String, String)

SelectCommand接続文字列指定してSqlDataAdapter クラス新しインスタンス初期化します。

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

Public Sub New ( _
    selectCommandText As String, _
    selectConnectionString As String _
)
Dim selectCommandText As String
Dim selectConnectionString As String

Dim instance As New SqlDataAdapter(selectCommandText,
 selectConnectionString)
public SqlDataAdapter (
    string selectCommandText,
    string selectConnectionString
)
public:
SqlDataAdapter (
    String^ selectCommandText, 
    String^ selectConnectionString
)
public SqlDataAdapter (
    String selectCommandText, 
    String selectConnectionString
)
public function SqlDataAdapter (
    selectCommandText : String, 
    selectConnectionString : String
)

パラメータ

selectCommandText

Transact-SQL SELECT ステートメントまたはストアド プロシージャである String。SqlDataAdapter の SelectCommand プロパティによって使用されます。

selectConnectionString

接続文字列

解説解説

SqlDataAdapter コンストラクタのこのオーバーロードでは、selectCommandText パラメータ使用して SelectCommand プロパティ設定しますSqlDataAdapter は、selectConnectionString パラメータ使用して接続作成および維持します。

SqlDataAdapterインスタンス作成すると、次のように各読み書き可能プロパティ初期値設定されます。

プロパティ

初期値

MissingMappingAction

MissingMappingAction.Passthrough

MissingSchemaAction

MissingSchemaAction.Add

これらのプロパティの値は、各プロパティ個別呼び出して変更できます

使用例使用例

SqlDataAdapter作成し、そのプロパティ一部設定する例を次に示します

Public Function CreateSqlDataAdapter(ByVal
 commandText As String, _
    ByVal connectionString As String)
 As SqlDataAdapter

    Dim adapter As SqlDataAdapter = New
 SqlDataAdapter(commandText, connectionString)
    Dim connection As SqlConnection = adapter.SelectCommand.Connection

    adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey

    ' Create the commands.
    adapter.InsertCommand = New SqlCommand( _
        "INSERT INTO Customers (CustomerID, CompanyName) "
 & _
         "VALUES (@CustomerID, @CompanyName)", connection)

    adapter.UpdateCommand = New SqlCommand( _
        "UPDATE Customers SET CustomerID = @CustomerID, CompanyName
 = @CompanyName " & _
        "WHERE CustomerID = @oldCustomerID", connection)

    adapter.DeleteCommand = New SqlCommand( _
        "DELETE FROM Customers WHERE CustomerID = @CustomerID",
 connection)

    ' Create the parameters.
    adapter.InsertCommand.Parameters.Add("@CustomerID",
 _
        SqlDbType.Char, 5, "CustomerID")
    adapter.InsertCommand.Parameters.Add("@CompanyName",
 _
        SqlDbType.VarChar, 40, "CompanyName")

    adapter.UpdateCommand.Parameters.Add("@CustomerID",
 _
        SqlDbType.Char, 5, "CustomerID")
    adapter.UpdateCommand.Parameters.Add("@CompanyName",
 _
        SqlDbType.VarChar, 40, "CompanyName")
    adapter.UpdateCommand.Parameters.Add("@oldCustomerID",
 _
        SqlDbType.Char, 5, "CustomerID").SourceVersion = DataRowVersion.Original

    adapter.DeleteCommand.Parameters.Add("@CustomerID",
 _
        SqlDbType.Char, 5, "CustomerID").SourceVersion = DataRowVersion.Original

    Return adapter
End Function
public static SqlDataAdapter CreateSqlDataAdapter(string
 commandText,
    string connectionString)
{
    SqlDataAdapter adapter = new SqlDataAdapter(commandText, connectionString);
    SqlConnection connection = adapter.SelectCommand.Connection;

    adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;

    // Create the commands.
    adapter.InsertCommand = new SqlCommand(
        "INSERT INTO Customers (CustomerID, CompanyName) " +
        "VALUES (@CustomerID, @CompanyName)", connection);

    adapter.UpdateCommand = new SqlCommand(
        "UPDATE Customers SET CustomerID = @CustomerID, CompanyName = @CompanyName
 " +
        "WHERE CustomerID = @oldCustomerID", connection);

    adapter.DeleteCommand = new SqlCommand(
        "DELETE FROM Customers WHERE CustomerID = @CustomerID", connection);

    // Create the parameters.
    adapter.InsertCommand.Parameters.Add("@CustomerID", 
        SqlDbType.Char, 5, "CustomerID");
    adapter.InsertCommand.Parameters.Add("@CompanyName", 
        SqlDbType.VarChar, 40, "CompanyName");

    adapter.UpdateCommand.Parameters.Add("@CustomerID", 
        SqlDbType.Char, 5, "CustomerID");
    adapter.UpdateCommand.Parameters.Add("@CompanyName", 
        SqlDbType.VarChar, 40, "CompanyName");
    adapter.UpdateCommand.Parameters.Add("@oldCustomerID", 
        SqlDbType.Char, 5, "CustomerID").SourceVersion = DataRowVersion.Original;

    adapter.DeleteCommand.Parameters.Add("@CustomerID", 
        SqlDbType.Char, 5, "CustomerID").SourceVersion = DataRowVersion.Original;

    return adapter;
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

SqlDataAdapter コンストラクタ ()

SqlDataAdapter クラス新しインスタンス初期化します。

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

Dim instance As New SqlDataAdapter
public SqlDataAdapter ()
public:
SqlDataAdapter ()
public SqlDataAdapter ()
public function SqlDataAdapter ()
解説解説

SqlDataAdapterインスタンス作成すると、次のように各読み書き可能プロパティ初期値設定されます。

プロパティ

初期値

MissingMappingAction

MissingMappingAction.Passthrough

MissingSchemaAction

MissingSchemaAction.Add

これらのプロパティの値は、各プロパティ個別呼び出して変更できます

使用例使用例

SqlDataAdapter作成し、そのプロパティ一部設定する例を次に示します

Public Function CreateSqlDataAdapter(ByVal
 connection As SqlConnection) As SqlDataAdapter
    Dim adapter As SqlDataAdapter = New
 SqlDataAdapter
    adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey

    ' Create the commands.
    adapter.SelectCommand = New SqlCommand( _
        "SELECT CustomerID, CompanyName FROM CUSTOMERS",
 connection)
    adapter.InsertCommand = New SqlCommand( _
        "INSERT INTO Customers (CustomerID, CompanyName) "
 & _
         "VALUES (@CustomerID, @CompanyName)", connection)
    adapter.UpdateCommand = New SqlCommand( _
        "UPDATE Customers SET CustomerID = @CustomerID, CompanyName
 = @CompanyName " & _
        "WHERE CustomerID = @oldCustomerID", connection)
    adapter.DeleteCommand = New SqlCommand( _
        "DELETE FROM Customers WHERE CustomerID = @CustomerID",
 connection)

    ' Create the parameters.
    adapter.InsertCommand.Parameters.Add("@CustomerID",
 _
        SqlDbType.Char, 5, "CustomerID")
    adapter.InsertCommand.Parameters.Add("@CompanyName",
 _
        SqlDbType.VarChar, 40, "CompanyName")

    adapter.UpdateCommand.Parameters.Add("@CustomerID",
 _
        SqlDbType.Char, 5, "CustomerID")
    adapter.UpdateCommand.Parameters.Add("@CompanyName",
 _
        SqlDbType.VarChar, 40, "CompanyName")
    adapter.UpdateCommand.Parameters.Add("@oldCustomerID",
 _
        SqlDbType.Char, 5, "CustomerID").SourceVersion = DataRowVersion.Original

    adapter.DeleteCommand.Parameters.Add("@CustomerID",
 _
        SqlDbType.Char, 5, "CustomerID").SourceVersion = DataRowVersion.Original

    Return adapter
End Function
public static SqlDataAdapter CreateSqlDataAdapter(SqlConnection
 connection)
{
    SqlDataAdapter adapter = new SqlDataAdapter();
    adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;

    // Create the commands.
    adapter.SelectCommand = new SqlCommand(
        "SELECT CustomerID, CompanyName FROM CUSTOMERS", connection);
    adapter.InsertCommand = new SqlCommand(
        "INSERT INTO Customers (CustomerID, CompanyName) " +
        "VALUES (@CustomerID, @CompanyName)", connection);
    adapter.UpdateCommand = new SqlCommand(
        "UPDATE Customers SET CustomerID = @CustomerID, CompanyName = @CompanyName
 " +
        "WHERE CustomerID = @oldCustomerID", connection);
    adapter.DeleteCommand = new SqlCommand(
        "DELETE FROM Customers WHERE CustomerID = @CustomerID", connection);

    // Create the parameters.
    adapter.InsertCommand.Parameters.Add("@CustomerID", 
        SqlDbType.Char, 5, "CustomerID");
    adapter.InsertCommand.Parameters.Add("@CompanyName", 
        SqlDbType.VarChar, 40, "CompanyName");

    adapter.UpdateCommand.Parameters.Add("@CustomerID", 
        SqlDbType.Char, 5, "CustomerID");
    adapter.UpdateCommand.Parameters.Add("@CompanyName", 
        SqlDbType.VarChar, 40, "CompanyName");
    adapter.UpdateCommand.Parameters.Add("@oldCustomerID", 
        SqlDbType.Char, 5, "CustomerID").SourceVersion = DataRowVersion.Original;

    adapter.DeleteCommand.Parameters.Add("@CustomerID", 
        SqlDbType.Char, 5, "CustomerID").SourceVersion = DataRowVersion.Original;

    return adapter;
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



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

辞書ショートカット

すべての辞書の索引

「SqlDataAdapter コンストラクタ」の関連用語

SqlDataAdapter コンストラクタのお隣キーワード
検索ランキング

   

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



SqlDataAdapter コンストラクタのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2024 GRAS Group, Inc.RSS