SqlDataAdapter Constructor (SqlCommand)
Assembly: System.Data (in System.Data.dll)
When an instance of SqlDataAdapter is created, the following read/write properties are set to the following initial values.
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 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
Available since 1.1