Partilhar via


OdbcDataAdapter Construtores

Definição

Inicializa uma nova instância da classe OdbcDataAdapter.

Sobrecargas

OdbcDataAdapter()

Inicializa uma nova instância da classe OdbcDataAdapter.

OdbcDataAdapter(OdbcCommand)

Inicializa uma nova instância da classe OdbcDataAdapter com a instrução SQL SELECT especificada.

OdbcDataAdapter(String, OdbcConnection)

Inicializa uma nova instância da classe OdbcDataAdapter com a instrução SQL SELECT e um OdbcConnection.

OdbcDataAdapter(String, String)

Inicializa uma nova instância da classe OdbcDataAdapter com uma instrução SQL SELECT e uma cadeia de conexão.

OdbcDataAdapter()

Origem:
OdbcDataAdapter.cs
Origem:
OdbcDataAdapter.cs
Origem:
OdbcDataAdapter.cs
Origem:
OdbcDataAdapter.cs
Origem:
OdbcDataAdapter.cs

Inicializa uma nova instância da classe OdbcDataAdapter.

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

Exemplos

O exemplo a seguir cria um OdbcDataAdapter e define algumas de suas propriedades.

public static OdbcDataAdapter CreateDataAdapter(
    OdbcConnection connection)
{
    string selectCommand =
        "SELECT CustomerID, CompanyName FROM Customers";

    OdbcDataAdapter adapter = new OdbcDataAdapter(
        selectCommand, connection);
    adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;

    // Create the Insert, Update and Delete commands.
    adapter.InsertCommand = new OdbcCommand(
        "INSERT INTO Customers (CustomerID, CompanyName) " +
        "VALUES (?, ?)");

    adapter.UpdateCommand = new OdbcCommand(
        "UPDATE Customers SET CustomerID = ?, CompanyName = ? " +
        "WHERE CustomerID = ?");

    adapter.DeleteCommand = new OdbcCommand(
        "DELETE FROM Customers WHERE CustomerID = ?");

    // Create the parameters.
    adapter.InsertCommand.Parameters.Add("@CustomerID",
        OdbcType.Char, 5, "CustomerID");
    adapter.InsertCommand.Parameters.Add("@CompanyName",
        OdbcType.VarChar, 40, "CompanyName");

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

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

    return adapter;
}
Public Function CreateDataAdapter( _
    ByVal connection As OdbcConnection) As OdbcDataAdapter

    Dim selectCommand As String = _
        "SELECT CustomerID, CompanyName FROM Customers"
    Dim adapter As OdbcDataAdapter = _
        New OdbcDataAdapter(selectCommand, connection)

    adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey

    ' Create the Insert, Update and Delete commands.
    adapter.InsertCommand = New OdbcCommand( _
        "INSERT INTO Customers (CustomerID, CompanyName) " & _
         "VALUES (?, ?)")

    adapter.UpdateCommand = New OdbcCommand( _
        "UPDATE Customers SET CustomerID = ?, CompanyName = ? " & _
        "WHERE CustomerID = ?")

    adapter.DeleteCommand = New OdbcCommand( _
        "DELETE FROM Customers WHERE CustomerID = ?")

    ' Create the parameters.
    adapter.InsertCommand.Parameters.Add( _
        "@CustomerID", OdbcType.Char, 5, "CustomerID")
    adapter.InsertCommand.Parameters.Add( _
        "@CompanyName", OdbcType.VarChar, 40, "CompanyName")

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

    adapter.DeleteCommand.Parameters.Add( _
        "@CustomerID", OdbcType.Char, 5, "CustomerID").SourceVersion = _
        DataRowVersion.Original

    Return adapter
End Function

Comentários

Quando você cria uma instância do OdbcDataAdapter, as propriedades somente gravação e somente leitura a seguir são definidas com seus valores padrão, conforme mostrado na tabela.

Propriedades Valor padrão
MissingMappingAction MissingMappingAction.Passthrough
MissingSchemaAction MissingSchemaAction.Add

Você pode alterar o valor de qualquer uma dessas propriedades por meio de uma chamada separada para a propriedade .

Confira também

Aplica-se a

OdbcDataAdapter(OdbcCommand)

Origem:
OdbcDataAdapter.cs
Origem:
OdbcDataAdapter.cs
Origem:
OdbcDataAdapter.cs
Origem:
OdbcDataAdapter.cs
Origem:
OdbcDataAdapter.cs

Inicializa uma nova instância da classe OdbcDataAdapter com a instrução SQL SELECT especificada.

public:
 OdbcDataAdapter(System::Data::Odbc::OdbcCommand ^ selectCommand);
public OdbcDataAdapter (System.Data.Odbc.OdbcCommand? selectCommand);
public OdbcDataAdapter (System.Data.Odbc.OdbcCommand selectCommand);
new System.Data.Odbc.OdbcDataAdapter : System.Data.Odbc.OdbcCommand -> System.Data.Odbc.OdbcDataAdapter
Public Sub New (selectCommand As OdbcCommand)

Parâmetros

selectCommand
OdbcCommand

Um OdbcCommand que é uma instrução SQL SELECT ou um procedimento armazenado e é definida como a propriedade SelectCommand do OdbcDataAdapter.

Exemplos

O exemplo a seguir cria um OdbcDataAdapter e define algumas de suas propriedades.

public static OdbcDataAdapter CreateDataAdapter(
    OdbcConnection connection)
{
    string selectCommand =
        "SELECT CustomerID, CompanyName FROM Customers";

    OdbcDataAdapter adapter = new OdbcDataAdapter(
        selectCommand, connection);
    adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;

    // Create the Insert, Update and Delete commands.
    adapter.InsertCommand = new OdbcCommand(
        "INSERT INTO Customers (CustomerID, CompanyName) " +
        "VALUES (?, ?)");

    adapter.UpdateCommand = new OdbcCommand(
        "UPDATE Customers SET CustomerID = ?, CompanyName = ? " +
        "WHERE CustomerID = ?");

    adapter.DeleteCommand = new OdbcCommand(
        "DELETE FROM Customers WHERE CustomerID = ?");

    // Create the parameters.
    adapter.InsertCommand.Parameters.Add("@CustomerID",
        OdbcType.Char, 5, "CustomerID");
    adapter.InsertCommand.Parameters.Add("@CompanyName",
        OdbcType.VarChar, 40, "CompanyName");

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

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

    return adapter;
}
Public Function CreateDataAdapter( _
    ByVal connection As OdbcConnection) As OdbcDataAdapter

    Dim selectCommand As String = _
        "SELECT CustomerID, CompanyName FROM Customers"
    Dim adapter As OdbcDataAdapter = _
        New OdbcDataAdapter(selectCommand, connection)

    adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey

    ' Create the Insert, Update and Delete commands.
    adapter.InsertCommand = New OdbcCommand( _
        "INSERT INTO Customers (CustomerID, CompanyName) " & _
         "VALUES (?, ?)")

    adapter.UpdateCommand = New OdbcCommand( _
        "UPDATE Customers SET CustomerID = ?, CompanyName = ? " & _
        "WHERE CustomerID = ?")

    adapter.DeleteCommand = New OdbcCommand( _
        "DELETE FROM Customers WHERE CustomerID = ?")

    ' Create the parameters.
    adapter.InsertCommand.Parameters.Add( _
        "@CustomerID", OdbcType.Char, 5, "CustomerID")
    adapter.InsertCommand.Parameters.Add( _
        "@CompanyName", OdbcType.VarChar, 40, "CompanyName")

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

    adapter.DeleteCommand.Parameters.Add( _
        "@CustomerID", OdbcType.Char, 5, "CustomerID").SourceVersion = _
        DataRowVersion.Original

    Return adapter
End Function

Comentários

Essa implementação do OdbcDataAdapter construtor define a SelectCommand propriedade como o valor especificado no selectCommand parâmetro .

Quando você cria uma instância do OdbcDataAdapter, as propriedades somente gravação e somente leitura a seguir são definidas com seus valores padrão, conforme mostrado na tabela.

Propriedades Valor inicial
MissingMappingAction MissingMappingAction.Passthrough
MissingSchemaAction MissingSchemaAction.Add

Você pode alterar o valor de qualquer uma dessas propriedades por meio de uma chamada separada para a propriedade .

Confira também

Aplica-se a

OdbcDataAdapter(String, OdbcConnection)

Origem:
OdbcDataAdapter.cs
Origem:
OdbcDataAdapter.cs
Origem:
OdbcDataAdapter.cs
Origem:
OdbcDataAdapter.cs
Origem:
OdbcDataAdapter.cs

Inicializa uma nova instância da classe OdbcDataAdapter com a instrução SQL SELECT e um OdbcConnection.

public:
 OdbcDataAdapter(System::String ^ selectCommandText, System::Data::Odbc::OdbcConnection ^ selectConnection);
public OdbcDataAdapter (string? selectCommandText, System.Data.Odbc.OdbcConnection? selectConnection);
public OdbcDataAdapter (string selectCommandText, System.Data.Odbc.OdbcConnection selectConnection);
new System.Data.Odbc.OdbcDataAdapter : string * System.Data.Odbc.OdbcConnection -> System.Data.Odbc.OdbcDataAdapter
Public Sub New (selectCommandText As String, selectConnection As OdbcConnection)

Parâmetros

selectCommandText
String

Uma cadeia de caracteres que é uma instrução SQL SELECT ou um procedimento armazenado a ser usado pela propriedade SelectCommand do OdbcDataAdapter.

selectConnection
OdbcConnection

Um OdbcConnection que representa a conexão.

Exemplos

O exemplo a seguir cria um OdbcDataAdapter e define algumas de suas propriedades.

public static OdbcDataAdapter CreateDataAdapter(
    OdbcConnection connection)
{
    string selectCommand =
        "SELECT CustomerID, CompanyName FROM Customers";

    OdbcDataAdapter adapter = new OdbcDataAdapter(
        selectCommand, connection);
    adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;

    // Create the Insert, Update and Delete commands.
    adapter.InsertCommand = new OdbcCommand(
        "INSERT INTO Customers (CustomerID, CompanyName) " +
        "VALUES (?, ?)");

    adapter.UpdateCommand = new OdbcCommand(
        "UPDATE Customers SET CustomerID = ?, CompanyName = ? " +
        "WHERE CustomerID = ?");

    adapter.DeleteCommand = new OdbcCommand(
        "DELETE FROM Customers WHERE CustomerID = ?");

    // Create the parameters.
    adapter.InsertCommand.Parameters.Add("@CustomerID",
        OdbcType.Char, 5, "CustomerID");
    adapter.InsertCommand.Parameters.Add("@CompanyName",
        OdbcType.VarChar, 40, "CompanyName");

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

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

    return adapter;
}
Public Function CreateDataAdapter( _
    ByVal connection As OdbcConnection) As OdbcDataAdapter

    Dim selectCommand As String = _
        "SELECT CustomerID, CompanyName FROM Customers"
    Dim adapter As OdbcDataAdapter = _
        New OdbcDataAdapter(selectCommand, connection)

    adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey

    ' Create the Insert, Update and Delete commands.
    adapter.InsertCommand = New OdbcCommand( _
        "INSERT INTO Customers (CustomerID, CompanyName) " & _
         "VALUES (?, ?)")

    adapter.UpdateCommand = New OdbcCommand( _
        "UPDATE Customers SET CustomerID = ?, CompanyName = ? " & _
        "WHERE CustomerID = ?")

    adapter.DeleteCommand = New OdbcCommand( _
        "DELETE FROM Customers WHERE CustomerID = ?")

    ' Create the parameters.
    adapter.InsertCommand.Parameters.Add( _
        "@CustomerID", OdbcType.Char, 5, "CustomerID")
    adapter.InsertCommand.Parameters.Add( _
        "@CompanyName", OdbcType.VarChar, 40, "CompanyName")

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

    adapter.DeleteCommand.Parameters.Add( _
        "@CustomerID", OdbcType.Char, 5, "CustomerID").SourceVersion = _
        DataRowVersion.Original

    Return adapter
End Function

Comentários

Essa implementação do OdbcDataAdapter pode ser útil em um aplicativo que deve chamar o Fill método para dois ou mais OdbcDataAdapter objetos.

Confira também

Aplica-se a

OdbcDataAdapter(String, String)

Origem:
OdbcDataAdapter.cs
Origem:
OdbcDataAdapter.cs
Origem:
OdbcDataAdapter.cs
Origem:
OdbcDataAdapter.cs
Origem:
OdbcDataAdapter.cs

Inicializa uma nova instância da classe OdbcDataAdapter com uma instrução SQL SELECT e uma cadeia de conexão.

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

Parâmetros

selectCommandText
String

Uma cadeia de caracteres que é uma instrução SQL SELECT ou um procedimento armazenado a ser usado pela propriedade SelectCommand do OdbcDataAdapter.

selectConnectionString
String

A cadeia de conexão.

Exemplos

O exemplo a seguir cria um OdbcDataAdapter e define algumas de suas propriedades.

public static OdbcDataAdapter CreateDataAdapter(
    OdbcConnection connection)
{
    string selectCommand =
        "SELECT CustomerID, CompanyName FROM Customers";

    OdbcDataAdapter adapter = new OdbcDataAdapter(
        selectCommand, connection);
    adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;

    // Create the Insert, Update and Delete commands.
    adapter.InsertCommand = new OdbcCommand(
        "INSERT INTO Customers (CustomerID, CompanyName) " +
        "VALUES (?, ?)");

    adapter.UpdateCommand = new OdbcCommand(
        "UPDATE Customers SET CustomerID = ?, CompanyName = ? " +
        "WHERE CustomerID = ?");

    adapter.DeleteCommand = new OdbcCommand(
        "DELETE FROM Customers WHERE CustomerID = ?");

    // Create the parameters.
    adapter.InsertCommand.Parameters.Add("@CustomerID",
        OdbcType.Char, 5, "CustomerID");
    adapter.InsertCommand.Parameters.Add("@CompanyName",
        OdbcType.VarChar, 40, "CompanyName");

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

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

    return adapter;
}
Public Function CreateDataAdapter( _
    ByVal connection As OdbcConnection) As OdbcDataAdapter

    Dim selectCommand As String = _
        "SELECT CustomerID, CompanyName FROM Customers"
    Dim adapter As OdbcDataAdapter = _
        New OdbcDataAdapter(selectCommand, connection)

    adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey

    ' Create the Insert, Update and Delete commands.
    adapter.InsertCommand = New OdbcCommand( _
        "INSERT INTO Customers (CustomerID, CompanyName) " & _
         "VALUES (?, ?)")

    adapter.UpdateCommand = New OdbcCommand( _
        "UPDATE Customers SET CustomerID = ?, CompanyName = ? " & _
        "WHERE CustomerID = ?")

    adapter.DeleteCommand = New OdbcCommand( _
        "DELETE FROM Customers WHERE CustomerID = ?")

    ' Create the parameters.
    adapter.InsertCommand.Parameters.Add( _
        "@CustomerID", OdbcType.Char, 5, "CustomerID")
    adapter.InsertCommand.Parameters.Add( _
        "@CompanyName", OdbcType.VarChar, 40, "CompanyName")

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

    adapter.DeleteCommand.Parameters.Add( _
        "@CustomerID", OdbcType.Char, 5, "CustomerID").SourceVersion = _
        DataRowVersion.Original

    Return adapter
End Function

Comentários

Essa sobrecarga do OdbcDataAdapter construtor usa o selectConnectionString parâmetro para definir a SelectCommand propriedade . No entanto, ele não abre a conexão. Você ainda deve abrir explicitamente a conexão.

Confira também

Aplica-se a