Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
OleDbDataAdapter Constructor

OleDbDataAdapter Constructor

.NET Framework 1.1

Initializes a new instance of the OleDbDataAdapter class.

Overload List

Initializes a new instance of the OleDbDataAdapter class.

[Visual Basic] Public Sub New()
[C#] public OleDbDataAdapter();
[C++] public: OleDbDataAdapter();
[JScript] public function OleDbDataAdapter();

Initializes a new instance of the OleDbDataAdapter class with the specified OleDbCommand as the SelectCommand property.

[Visual Basic] Public Sub New(OleDbCommand)
[C#] public OleDbDataAdapter(OleDbCommand);
[C++] public: OleDbDataAdapter(OleDbCommand*);
[JScript] public function OleDbDataAdapter(OleDbCommand);

Initializes a new instance of the OleDbDataAdapter class with a SelectCommand.

[Visual Basic] Public Sub New(String, OleDbConnection)
[C#] public OleDbDataAdapter(string, OleDbConnection);
[C++] public: OleDbDataAdapter(String*, OleDbConnection*);
[JScript] public function OleDbDataAdapter(String, OleDbConnection);

Initializes a new instance of the OleDbDataAdapter class with a SelectCommand.

[Visual Basic] Public Sub New(String, String)
[C#] public OleDbDataAdapter(string, string);
[C++] public: OleDbDataAdapter(String*, String*);
[JScript] public function OleDbDataAdapter(String, String);

Example

[Visual Basic, C#, C++] The following example creates an OleDbDataAdapter and sets some of its properties.

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of the OleDbDataAdapter constructor. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
Public Sub CreateOleDbDataAdapter()
    nwindConn = New OleDbConnection()
    Dim mySelectText As String = "SELECT CustomerID, CompanyName FROM CUSTOMERS"
    Dim myConnString As String = "Provider=SQLOLEDB;Data Source=localhost;" & _
                                     "Integrated Security=SSPI;Initial Catalog=northwind"
    Dim custDA As OleDbDataAdapter = New OleDbDataAdapter(mySelectText, myConnString)
    custDA.MissingSchemaAction = MissingSchemaAction.AddWithKey    
   
    custDA.InsertCommand = New OleDbCommand("INSERT INTO Customers (CustomerID, CompanyName) " & _
                                            "VALUES (?, ?)", nwindConn)
    custDA.UpdateCommand = New OleDbCommand("UPDATE Customers SET CustomerID = ?, CompanyName = ? " & _
                                            "WHERE CustomerID = ?", nwindConn)
    custDA.DeleteCommand = New OleDbCommand("DELETE FROM Customers WHERE CustomerID = ?", nwindConn)

    custDA.InsertCommand.Parameters.Add("@CustomerID", OleDbType.Char, 5, "CustomerID")
    custDA.InsertCommand.Parameters.Add("@CompanyName", OleDbType.VarChar, 40, "CompanyName")
 
    custDA.UpdateCommand.Parameters.Add("@CustomerID", OleDbType.Char, 5, "CustomerID")
    custDA.UpdateCommand.Parameters.Add("@CompanyName", OleDbType.VarChar, 40, "CompanyName")
    custDA.UpdateCommand.Parameters.Add("@oldCustomerID", OleDbType.Char, 5, "CustomerID").SourceVersion = DataRowVersion.Original

    custDA.DeleteCommand.Parameters.Add("@CustomerID", OleDbType.Char, 5, "CustomerID").SourceVersion = DataRowVersion.Original
End Sub

[C#] 
public void CreateOleDbDataAdapter() 
{
    nwindConn = new OleDbConnection();

    string mySelectText = "SELECT CustomerID, CompanyName FROM CUSTOMERS";
    string myConnString = "Provider=SQLOLEDB;Data Source=localhost;" +
                          "Integrated Security=SSPI;Initial Catalog=northwind";
    OleDbDataAdapter custDA = new OleDbDataAdapter(mySelectText, myConnString);
    custDA.MissingSchemaAction = MissingSchemaAction.AddWithKey;
   
    custDA.InsertCommand = new OleDbCommand("INSERT INTO Customers (CustomerID, CompanyName) " +
                                            "VALUES (?, ?)", nwindConn);
    custDA.UpdateCommand = new OleDbCommand("UPDATE Customers SET CustomerID = ?, CompanyName = ? " +
                                            "WHERE CustomerID = ?", nwindConn);
    custDA.DeleteCommand = new OleDbCommand("DELETE FROM Customers WHERE CustomerID = ?", nwindConn);

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

    custDA.DeleteCommand.Parameters.Add("@CustomerID", OleDbType.Char, 5, "CustomerID").SourceVersion = DataRowVersion.Original;
}

[C++] 
public:
void CreateOleDbDataAdapter() 
{
    nwindConn = new OleDbConnection();

    String* mySelectText = S"SELECT CustomerID, CompanyName FROM CUSTOMERS";
    String* myConnString = S"Provider=SQLOLEDB;Data Source=localhost;" 
                           S"Integrated Security=SSPI;Initial Catalog=northwind";
    OleDbDataAdapter* custDA = new OleDbDataAdapter(mySelectText, myConnString);
    custDA->MissingSchemaAction = MissingSchemaAction::AddWithKey;
   
    custDA->InsertCommand = new OleDbCommand(S"INSERT INTO Customers (CustomerID, CompanyName) " 
                                             S"VALUES (?, ?)", nwindConn);
    custDA->UpdateCommand = new OleDbCommand(S"UPDATE Customers SET CustomerID = ?, CompanyName = ? " 
                                             S"WHERE CustomerID = ?", nwindConn);
    custDA->DeleteCommand = new OleDbCommand(S"DELETE FROM Customers WHERE CustomerID = ?", nwindConn);

    custDA->InsertCommand->Parameters->Add(S"@CustomerID", OleDbType::Char, 5, S"CustomerID");
    custDA->InsertCommand->Parameters->Add(S"@CompanyName", OleDbType::VarChar, 40, S"CompanyName");
 
    custDA->UpdateCommand->Parameters->Add(S"@CustomerID", OleDbType::Char, 5, S"CustomerID");
    custDA->UpdateCommand->Parameters->Add(S"@CompanyName", OleDbType::VarChar, 40, S"CompanyName");
    custDA->UpdateCommand->Parameters->Add(S"@oldCustomerID", OleDbType::Char, 5, S"CustomerID")->SourceVersion = DataRowVersion::Original;

    custDA->DeleteCommand->Parameters->Add(S"@CustomerID", OleDbType::Char, 5, S"CustomerID")->SourceVersion = DataRowVersion::Original;
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

OleDbDataAdapter Class | OleDbDataAdapter Members | System.Data.OleDb Namespace

Show:
© 2015 Microsoft