OdbcDataAdapter Oluşturucular

Tanım

OdbcDataAdapter sınıfının yeni bir örneğini başlatır.

Aşırı Yüklemeler

OdbcDataAdapter()

OdbcDataAdapter sınıfının yeni bir örneğini başlatır.

OdbcDataAdapter(OdbcCommand)

Belirtilen SQL SELECT deyimiyle sınıfının yeni bir örneğini OdbcDataAdapter başlatır.

OdbcDataAdapter(String, OdbcConnection)

SQL SELECT deyimi ve OdbcConnectionile sınıfının yeni bir örneğini OdbcDataAdapter başlatır.

OdbcDataAdapter(String, String)

SQL SELECT deyimi ve bağlantı dizesi ile sınıfının yeni bir örneğini OdbcDataAdapter başlatır.

OdbcDataAdapter()

Kaynak:
OdbcDataAdapter.cs
Kaynak:
OdbcDataAdapter.cs

OdbcDataAdapter sınıfının yeni bir örneğini başlatır.

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

Örnekler

Aşağıdaki örnek bir OdbcDataAdapter oluşturur ve bazı özelliklerini ayarlar.

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

Açıklamalar

örneğini OdbcDataAdapteroluşturduğunuzda, aşağıdaki salt yazma ve salt okunur özellikler, tabloda gösterildiği gibi varsayılan değerlerine ayarlanır.

Özellikler Varsayılan değer
MissingMappingAction MissingMappingAction.Passthrough
MissingSchemaAction MissingSchemaAction.Add

Özelliğine ayrı bir çağrı aracılığıyla bu özelliklerden herhangi birinin değerini değiştirebilirsiniz.

Ayrıca bkz.

Şunlara uygulanır

OdbcDataAdapter(OdbcCommand)

Kaynak:
OdbcDataAdapter.cs
Kaynak:
OdbcDataAdapter.cs

Belirtilen SQL SELECT deyimiyle sınıfının yeni bir örneğini OdbcDataAdapter başlatır.

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)

Parametreler

selectCommand
OdbcCommand

SQL OdbcCommand SELECT deyimi veya saklı yordam olan ve özelliği OdbcDataAdapterolarak SelectCommand ayarlanan.

Örnekler

Aşağıdaki örnek bir OdbcDataAdapter oluşturur ve bazı özelliklerini ayarlar.

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

Açıklamalar

Oluşturucunun OdbcDataAdapter bu uygulaması, özelliğini parametresinde belirtilen değere selectCommand ayarlarSelectCommand.

örneğini OdbcDataAdapteroluşturduğunuzda, aşağıdaki salt yazma ve salt okunur özellikler, tabloda gösterildiği gibi varsayılan değerlerine ayarlanır.

Özellikler İlk değer
MissingMappingAction MissingMappingAction.Passthrough
MissingSchemaAction MissingSchemaAction.Add

Özelliğine ayrı bir çağrı aracılığıyla bu özelliklerden herhangi birinin değerini değiştirebilirsiniz.

Ayrıca bkz.

Şunlara uygulanır

OdbcDataAdapter(String, OdbcConnection)

Kaynak:
OdbcDataAdapter.cs
Kaynak:
OdbcDataAdapter.cs

SQL SELECT deyimi ve OdbcConnectionile sınıfının yeni bir örneğini OdbcDataAdapter başlatır.

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)

Parametreler

selectCommandText
String

özelliği OdbcDataAdaptertarafından SelectCommand kullanılacak bir SQL SELECT deyimi veya saklı yordam olan bir dize.

selectConnection
OdbcConnection

OdbcConnection Bağlantıyı temsil eden bir.

Örnekler

Aşağıdaki örnek bir OdbcDataAdapter oluşturur ve bazı özelliklerini ayarlar.

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

Açıklamalar

bu OdbcDataAdapter uygulaması, iki veya daha fazla OdbcDataAdapter nesne için yöntemini çağırması Fill gereken bir uygulamada yararlı olabilir.

Ayrıca bkz.

Şunlara uygulanır

OdbcDataAdapter(String, String)

Kaynak:
OdbcDataAdapter.cs
Kaynak:
OdbcDataAdapter.cs

SQL SELECT deyimi ve bağlantı dizesi ile sınıfının yeni bir örneğini OdbcDataAdapter başlatır.

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)

Parametreler

selectCommandText
String

özelliği OdbcDataAdaptertarafından SelectCommand kullanılacak bir SQL SELECT deyimi veya saklı yordam olan bir dize.

selectConnectionString
String

Bağlantı dizesi.

Örnekler

Aşağıdaki örnek bir OdbcDataAdapter oluşturur ve bazı özelliklerini ayarlar.

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

Açıklamalar

Oluşturucunun OdbcDataAdapter bu aşırı yüklemesi, özelliğini ayarlamak için parametresini SelectCommand kullanırselectConnectionString. Ancak, bağlantıyı açmaz. Yine de bağlantıyı açıkça açmanız gerekir.

Ayrıca bkz.

Şunlara uygulanır