SqlDataAdapter Constructor (SqlCommand)
Collapse the table of content
Expand the table of content

SqlDataAdapter.SqlDataAdapter(SqlCommand) Constructor

Initializes a new instance of the SqlDataAdapter class with the specified SqlCommand as the SelectCommand property.

Namespace: System.Data.SqlClient
Assembly: System.Data (in system.data.dll)

public SqlDataAdapter (
	SqlCommand selectCommand
public SqlDataAdapter (
	SqlCommand selectCommand
public function SqlDataAdapter (
	selectCommand : SqlCommand
Not applicable.



A SqlCommand that is a Transact-SQL SELECT statement or stored procedure and is set as the SelectCommand property of the SqlDataAdapter.

This implementation of the SqlDataAdapter constructor sets the SelectCommand property to the value specified in the selectCommand parameter.

When an instance of SqlDataAdapter is created, the following read/write properties are set to the following initial values.


Initial value





You can change the value of any of these properties through a separate call to the property.

When SelectCommand (or any of the other command properties) is assigned to a previously created SqlCommand, the SqlCommand is not cloned. The SelectCommand maintains a reference to the previously created SqlCommand object.

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.
        SqlDbType.Char, 5, "CustomerID");
        SqlDbType.VarChar, 40, "CompanyName");

        SqlDbType.Char, 5, "CustomerID");
        SqlDbType.VarChar, 40, "CompanyName");
        SqlDbType.Char, 5, "CustomerID").SourceVersion = DataRowVersion.Original;

        SqlDbType.Char, 5, "CustomerID").SourceVersion = DataRowVersion.Original;

    return adapter;

Windows 98, Windows Server 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

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

© 2016 Microsoft