SqlDataAdapter SqlDataAdapter SqlDataAdapter SqlDataAdapter Constructors

定義

オーバーロード

SqlDataAdapter() SqlDataAdapter() SqlDataAdapter()

SqlDataAdapter クラスの新しいインスタンスを初期化します。Initializes a new instance of the SqlDataAdapter class.

SqlDataAdapter(SqlCommand) SqlDataAdapter(SqlCommand) SqlDataAdapter(SqlCommand) SqlDataAdapter(SqlCommand)

SqlDataAdapter プロパティとして SqlCommand を指定して、SelectCommand クラスの新しいインスタンスを初期化します。Initializes a new instance of the SqlDataAdapter class with the specified SqlCommand as the SelectCommand property.

SqlDataAdapter(String, SqlConnection) SqlDataAdapter(String, SqlConnection) SqlDataAdapter(String, SqlConnection) SqlDataAdapter(String, SqlConnection)

SqlDataAdapter オブジェクトと SelectCommand オブジェクトを指定して、SqlConnection クラスの新しいインスタンスを初期化します。Initializes a new instance of the SqlDataAdapter class with a SelectCommand and a SqlConnection object.

SqlDataAdapter(String, String) SqlDataAdapter(String, String) SqlDataAdapter(String, String) SqlDataAdapter(String, String)

SqlDataAdapter と接続文字列を指定して、SelectCommand クラスの新しいインスタンスを初期化します。Initializes a new instance of the SqlDataAdapter class with a SelectCommand and a connection string.

SqlDataAdapter() SqlDataAdapter() SqlDataAdapter()

SqlDataAdapter クラスの新しいインスタンスを初期化します。Initializes a new instance of the SqlDataAdapter class.

public:
 SqlDataAdapter();
public SqlDataAdapter ();
Public Sub New ()

次の例ではSqlDataAdapter 、を作成し、そのプロパティの一部を設定します。The following example creates a SqlDataAdapter and sets some of its properties.

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;
}
Public Function CreateSqlDataAdapter( _
    ByVal connection As SqlConnection) As SqlDataAdapter

    Dim adapter As 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

注釈

SqlDataAdapterインスタンスが作成されると、次の読み取り/書き込みプロパティは、次の初期値に設定されます。When an instance of SqlDataAdapter is created, the following read/write properties are set to the following initial values.

プロパティProperties 初期値Initial value
MissingMappingAction MissingMappingAction.Passthrough
MissingSchemaAction MissingSchemaAction.Add

プロパティの別の呼び出しを使用して、これらのプロパティの値を変更できます。You can change the value of any of these properties through a separate call to the property.

こちらもご覧ください

SqlDataAdapter(SqlCommand) SqlDataAdapter(SqlCommand) SqlDataAdapter(SqlCommand) SqlDataAdapter(SqlCommand)

SqlDataAdapter プロパティとして SqlCommand を指定して、SelectCommand クラスの新しいインスタンスを初期化します。Initializes a new instance of the SqlDataAdapter class with the specified SqlCommand as the SelectCommand property.

public:
 SqlDataAdapter(System::Data::SqlClient::SqlCommand ^ selectCommand);
public SqlDataAdapter (System.Data.SqlClient.SqlCommand selectCommand);
new System.Data.SqlClient.SqlDataAdapter : System.Data.SqlClient.SqlCommand -> System.Data.SqlClient.SqlDataAdapter
Public Sub New (selectCommand As SqlCommand)

パラメーター

selectCommand
SqlCommand SqlCommand SqlCommand SqlCommand

Transact-SQL SELECT ステートメントまたはストアド プロシージャである SqlCommandSelectCommandSqlDataAdapter プロパティとして設定されます。A SqlCommand that is a Transact-SQL SELECT statement or stored procedure and is set as the SelectCommand property of the SqlDataAdapter.

次の例ではSqlDataAdapter 、を作成し、そのプロパティの一部を設定します。The following example creates a SqlDataAdapter and sets some of its properties.

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;
}
Public Function CreateSqlDataAdapter(ByVal selectCommand As SqlCommand, _
    ByVal connection As SqlConnection) As SqlDataAdapter

    Dim adapter As 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

注釈

このコンストラクターの実装SqlDataAdapterは、 SelectCommandプロパティをselectCommandパラメーターに指定された値に設定します。This implementation of the SqlDataAdapter constructor sets the SelectCommand property to the value specified in the selectCommand parameter.

SqlDataAdapterインスタンスが作成されると、次の読み取り/書き込みプロパティは、次の初期値に設定されます。When an instance of SqlDataAdapter is created, the following read/write properties are set to the following initial values.

プロパティProperties 初期値Initial value
MissingMappingAction MissingMappingAction.Passthrough
MissingSchemaAction MissingSchemaAction.Add

プロパティの別の呼び出しを使用して、これらのプロパティの値を変更できます。You can change the value of any of these properties through a separate call to the property.

以前SelectCommandに作成さSqlCommandれたに割り当てられている (または他のいずれSqlCommandかのコマンドプロパティ) 場合、は複製されません。When SelectCommand (or any of the other command properties) is assigned to a previously created SqlCommand, the SqlCommand is not cloned. SelectCommand 、以前に作成されたSqlCommandオブジェクトへの参照を保持します。The SelectCommand maintains a reference to the previously created SqlCommand object.

こちらもご覧ください

SqlDataAdapter(String, SqlConnection) SqlDataAdapter(String, SqlConnection) SqlDataAdapter(String, SqlConnection) SqlDataAdapter(String, SqlConnection)

SqlDataAdapter オブジェクトと SelectCommand オブジェクトを指定して、SqlConnection クラスの新しいインスタンスを初期化します。Initializes a new instance of the SqlDataAdapter class with a SelectCommand and a SqlConnection object.

public:
 SqlDataAdapter(System::String ^ selectCommandText, System::Data::SqlClient::SqlConnection ^ selectConnection);
public SqlDataAdapter (string selectCommandText, System.Data.SqlClient.SqlConnection selectConnection);
new System.Data.SqlClient.SqlDataAdapter : string * System.Data.SqlClient.SqlConnection -> System.Data.SqlClient.SqlDataAdapter
Public Sub New (selectCommandText As String, selectConnection As SqlConnection)

パラメーター

selectCommandText
String String String String

Transact-SQL SELECT ステートメントまたはストアド プロシージャである StringSelectCommandSqlDataAdapter プロパティによって使用されます。A String that is a Transact-SQL SELECT statement or stored procedure to be used by the SelectCommand property of the SqlDataAdapter.

selectConnection
SqlConnection SqlConnection SqlConnection SqlConnection

接続を表す SqlConnectionA SqlConnection that represents the connection. 接続文字列が Integrated Security = true を使用しない場合は、SqlCredential を使用すると、ユーザー ID とパスワードを接続文字列内のテキストとして指定する場合よりも安全に、ユーザー ID とパスワードを渡すことができます。If your connection string does not use Integrated Security = true, you can use SqlCredential to pass the user ID and password more securely than by specifying the user ID and password as text in the connection string.

次の例ではSqlDataAdapter 、を作成し、そのプロパティの一部を設定します。The following example creates a SqlDataAdapter and sets some of its properties.

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;
}
Public Function CreateSqlDataAdapter(ByVal commandText As String, _
    ByVal connection As SqlConnection) As SqlDataAdapter

    Dim adapter As 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

注釈

のこの実装SqlDataAdapterは、まだ開いてSqlConnectionいない場合はを開き、閉じます。This implementation of the SqlDataAdapter opens and closes a SqlConnection if it is not already open. これは、 Fill 2 つSqlDataAdapter以上のオブジェクトに対してメソッドを呼び出す必要があるアプリケーションで役に立ちます。This can be useful in an application that must call the Fill method for two or more SqlDataAdapter objects. が既に開いている場合は、close またはDispose を明示的に呼び出して閉じる必要があります。 **** SqlConnectionIf the SqlConnection is already open, you must explicitly call Close or Dispose to close it.

SqlDataAdapterインスタンスが作成されると、次の読み取り/書き込みプロパティは、次の初期値に設定されます。When an instance of SqlDataAdapter is created, the following read/write properties are set to the following initial values.

プロパティProperties 初期値Initial value
MissingMappingAction MissingMappingAction.Passthrough
MissingSchemaAction MissingSchemaAction.Add

プロパティの別の呼び出しを使用して、これらのプロパティのいずれかの値を変更できます。You can change the value of either of these properties through a separate call to the property.

こちらもご覧ください

SqlDataAdapter(String, String) SqlDataAdapter(String, String) SqlDataAdapter(String, String) SqlDataAdapter(String, String)

SqlDataAdapter と接続文字列を指定して、SelectCommand クラスの新しいインスタンスを初期化します。Initializes a new instance of the SqlDataAdapter class with a SelectCommand and a connection string.

public:
 SqlDataAdapter(System::String ^ selectCommandText, System::String ^ selectConnectionString);
public SqlDataAdapter (string selectCommandText, string selectConnectionString);
new System.Data.SqlClient.SqlDataAdapter : string * string -> System.Data.SqlClient.SqlDataAdapter
Public Sub New (selectCommandText As String, selectConnectionString As String)

パラメーター

selectCommandText
String String String String

Transact-SQL SELECT ステートメントまたはストアド プロシージャである StringSelectCommandSqlDataAdapter プロパティによって使用されます。A String that is a Transact-SQL SELECT statement or stored procedure to be used by the SelectCommand property of the SqlDataAdapter.

selectConnectionString
String String String String

接続文字列。The connection string. 接続文字列が Integrated Security = true を使用しない場合は、SqlDataAdapter(String, SqlConnection)SqlCredential を使用すると、ユーザー ID とパスワードを接続文字列内のテキストとして指定する場合よりも安全に、ユーザー ID とパスワードを渡すことができます。If your connection string does not use Integrated Security = true, you can use SqlDataAdapter(String, SqlConnection) and SqlCredential to pass the user ID and password more securely than by specifying the user ID and password as text in the connection string.

次の例ではSqlDataAdapter 、を作成し、そのプロパティの一部を設定します。The following example creates a SqlDataAdapter and sets some of its properties.

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;
}
Public Function CreateSqlDataAdapter(ByVal commandText As String, _
    ByVal connectionString As String) As SqlDataAdapter

    Dim adapter As 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

注釈

SqlDataAdapterコンストラクターのこのオーバーロードは、 selectCommandTextパラメーターを使用してSelectCommandプロパティを設定します。This overload of the SqlDataAdapter constructor uses the selectCommandText parameter to set the SelectCommand property. は、 selectConnectionStringパラメーターを使用して作成された接続を作成し、管理します。 SqlDataAdapterThe SqlDataAdapter will create and maintain the connection created with the selectConnectionString parameter.

SqlDataAdapterインスタンスが作成されると、次の読み取り/書き込みプロパティは、次の初期値に設定されます。When an instance of SqlDataAdapter is created, the following read/write properties are set to the following initial values.

プロパティProperties 初期値Initial value
MissingMappingAction MissingMappingAction.Passthrough
MissingSchemaAction MissingSchemaAction.Add

プロパティの別の呼び出しを使用して、これらのプロパティの値を変更できます。You can change the value of any of these properties through a separate call to the property.

こちらもご覧ください

適用対象