This documentation is archived and is not being maintained.

OdbcDataAdapter Constructor

.NET Framework 1.1
Note: This namespace, class, or member is supported only in version 1.1 of the .NET Framework.

Initializes a new instance of the OdbcDataAdapter class.

Overload List

Initializes a new instance of the OdbcDataAdapter class.

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

Initializes a new instance of the OdbcDataAdapter class with the specified SQL SELECT statement.

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

Initializes a new instance of the OdbcDataAdapter class with an SQL SELECT statement and an OdbcConnection.

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

Initializes a new instance of the OdbcDataAdapter class with an SQL SELECT statement and a connection string.

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

Example

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

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of the OdbcDataAdapter constructor. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
Public Sub CreateOdbcDataAdapter()
    Dim mySelectText As String = "SELECT CustomerID, CompanyName FROM CUSTOMERS"
    Dim myConnString As String = "DRIVER={SQL Server};SERVER=MyServer;Trusted_connection=yes;DATABASE=northwind;"
    Dim nwindConn As OdbcConnection = New OdbcConnection(myConnString)
    Dim custDA As OdbcDataAdapter = New OdbcDataAdapter(mySelectText, myConnString)

    custDA.MissingSchemaAction = MissingSchemaAction.AddWithKey    
   
    custDA.InsertCommand = New OdbcCommand("INSERT INTO Customers (CustomerID, CompanyName) " & _
                                            "VALUES (?, ?)", nwindConn)
    custDA.UpdateCommand = New OdbcCommand("UPDATE Customers SET CustomerID = ?, CompanyName = ? " & _
                                            "WHERE CustomerID = ?", nwindConn)
    custDA.DeleteCommand = New OdbcCommand("DELETE FROM Customers WHERE CustomerID = ?", nwindConn)

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

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

[C#] 
public static void CreateOdbcDataAdapter() 
{

    string mySelectText = "SELECT CustomerID, CompanyName FROM CUSTOMERS";
    string myConnString = "DRIVER={SQL Server};SERVER=MyServer;Trusted_connection=yes;DATABASE=northwind;";
    OdbcConnection nwindConn = new OdbcConnection(myConnString);
    OdbcDataAdapter custDA = new OdbcDataAdapter(mySelectText, myConnString);

    custDA.MissingSchemaAction = MissingSchemaAction.AddWithKey;
   
    custDA.InsertCommand = new OdbcCommand("INSERT INTO Customers (CustomerID, CompanyName) " +
                                            "VALUES (?, ?)", nwindConn);
    custDA.UpdateCommand = new OdbcCommand("UPDATE Customers SET CustomerID = ?, CompanyName = ? " +
                                            "WHERE CustomerID = ?", nwindConn);
    custDA.DeleteCommand = new OdbcCommand("DELETE FROM Customers WHERE CustomerID = ?", nwindConn);

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

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

[C++] 
public:
    static void CreateOdbcDataAdapter()
    {
        String* mySelectText = S"SELECT CustomerID, CompanyName FROM CUSTOMERS";
        String* myConnString = S"DRIVER= {SQL Server};SERVER=MyServer;Trusted_connection=yes;DATABASE=northwind;";
        OdbcConnection* nwindConn = new OdbcConnection(myConnString);
        OdbcDataAdapter* custDA = new OdbcDataAdapter(mySelectText, myConnString);

        custDA->MissingSchemaAction = MissingSchemaAction::AddWithKey;
        custDA->InsertCommand = new OdbcCommand(S"INSERT INTO Customers (CustomerID, CompanyName) VALUES (?, ?)", nwindConn);
        custDA->UpdateCommand = new OdbcCommand(S"UPDATE Customers SET CustomerID = ?, CompanyName = ? WHERE CustomerID = ?", nwindConn);
        custDA->DeleteCommand = new OdbcCommand(S"DELETE FROM Customers WHERE CustomerID = ?", nwindConn);

        custDA->InsertCommand->Parameters->Add(S"@CustomerID", OdbcType::Char, 5, S"CustomerID");
        custDA->InsertCommand->Parameters->Add(S"@CompanyName", OdbcType::VarChar, 40, S"CompanyName");

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

        custDA->DeleteCommand->Parameters->Add(S"@CustomerID", OdbcType::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

OdbcDataAdapter Class | OdbcDataAdapter Members | System.Data.Odbc Namespace

Show: