OleDbDataAdapter Konstruktory

Definicja

Inicjuje nowe wystąpienie klasy OleDbDataAdapter.

Przeciążenia

OleDbDataAdapter()

Inicjuje nowe wystąpienie klasy OleDbDataAdapter.

OleDbDataAdapter(OleDbCommand)

Inicjuje OleDbDataAdapter nowe wystąpienie klasy z określoną OleDbCommand właściwością SelectCommand .

OleDbDataAdapter(String, OleDbConnection)

Inicjuje OleDbDataAdapter nowe wystąpienie klasy za pomocą klasy SelectCommand.

OleDbDataAdapter(String, String)

Inicjuje OleDbDataAdapter nowe wystąpienie klasy za pomocą klasy SelectCommand.

OleDbDataAdapter()

Źródło:
OleDbDataAdapter.cs
Źródło:
OleDbDataAdapter.cs
Źródło:
OleDbDataAdapter.cs
Źródło:
OleDbDataAdapter.cs

Inicjuje nowe wystąpienie klasy OleDbDataAdapter.

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

Przykłady

Poniższy przykład tworzy obiekt OleDbDataAdapter i ustawia niektóre z jego właściwości.

public static OleDbDataAdapter CreateDataAdapter(
    OleDbConnection connection)
{
    string selectCommand =
        "SELECT CustomerID, CompanyName FROM Customers";
    OleDbDataAdapter adapter =
        new OleDbDataAdapter(selectCommand, connection);

    adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;

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

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

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

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

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

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

    return adapter;
}
Public Function CreateDataAdapter( _
    ByVal connection As OleDbConnection) As OleDbDataAdapter

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

    adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey

    ' Create the commands.
    adapter.InsertCommand = New OleDbCommand( _
        "INSERT INTO Customers (CustomerID, CompanyName) " & _
         "VALUES (?, ?)")

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

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

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

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

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

    Return adapter
End Function

Uwagi

Podczas tworzenia wystąpienia programu OleDbDataAdapternastępujące właściwości odczytu/zapisu są ustawione na następujące wartości początkowe.

Właściwości Wartość początkowa
MissingMappingAction MissingMappingAction.Passthrough
MissingSchemaAction MissingSchemaAction.Add

Wartość dowolnej z tych właściwości można zmienić za pomocą oddzielnego wywołania właściwości .

Zobacz też

Dotyczy

OleDbDataAdapter(OleDbCommand)

Źródło:
OleDbDataAdapter.cs
Źródło:
OleDbDataAdapter.cs
Źródło:
OleDbDataAdapter.cs
Źródło:
OleDbDataAdapter.cs

Inicjuje OleDbDataAdapter nowe wystąpienie klasy z określoną OleDbCommand właściwością SelectCommand .

public:
 OleDbDataAdapter(System::Data::OleDb::OleDbCommand ^ selectCommand);
public OleDbDataAdapter (System.Data.OleDb.OleDbCommand selectCommand);
public OleDbDataAdapter (System.Data.OleDb.OleDbCommand? selectCommand);
new System.Data.OleDb.OleDbDataAdapter : System.Data.OleDb.OleDbCommand -> System.Data.OleDb.OleDbDataAdapter
Public Sub New (selectCommand As OleDbCommand)

Parametry

selectCommand
OleDbCommand

Jest OleDbCommand to instrukcja SELECT lub procedura składowana, która jest ustawiana jako SelectCommand właściwość OleDbDataAdapter.

Przykłady

Poniższy przykład tworzy obiekt OleDbDataAdapter i ustawia niektóre z jego właściwości.

public static OleDbDataAdapter CreateDataAdapter(string selectCommand,
    OleDbConnection connection)
{
    OleDbDataAdapter adapter = new OleDbDataAdapter(selectCommand, connection);

    adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;

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

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

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

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

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

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

    return adapter;
}
Public Function CreateDataAdapter(ByVal selectCommand As String, _
    ByVal connection As OleDbConnection) As OleDbDataAdapter

    Dim adapter As OleDbDataAdapter = _
        New OleDbDataAdapter(selectCommand, connection)

    adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey

    ' Create the commands.
    adapter.InsertCommand = New OleDbCommand( _
        "INSERT INTO Customers (CustomerID, CompanyName) " & _
         "VALUES (?, ?)")

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

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

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

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

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

    Return adapter
End Function

Uwagi

Ta implementacja konstruktora OleDbDataAdapter ustawia SelectCommand właściwość na wartość określoną w parametrze selectCommand .

Podczas tworzenia wystąpienia programu OleDbDataAdapternastępujące właściwości odczytu/zapisu są ustawione na następujące wartości początkowe.

Właściwości Wartość początkowa
MissingMappingAction MissingMappingAction.Passthrough
MissingSchemaAction MissingSchemaAction.Add

Wartość dowolnej z tych właściwości można zmienić za pomocą oddzielnego wywołania właściwości .

Zobacz też

Dotyczy

OleDbDataAdapter(String, OleDbConnection)

Źródło:
OleDbDataAdapter.cs
Źródło:
OleDbDataAdapter.cs
Źródło:
OleDbDataAdapter.cs
Źródło:
OleDbDataAdapter.cs

Inicjuje OleDbDataAdapter nowe wystąpienie klasy za pomocą klasy SelectCommand.

public:
 OleDbDataAdapter(System::String ^ selectCommandText, System::Data::OleDb::OleDbConnection ^ selectConnection);
public OleDbDataAdapter (string selectCommandText, System.Data.OleDb.OleDbConnection selectConnection);
public OleDbDataAdapter (string? selectCommandText, System.Data.OleDb.OleDbConnection? selectConnection);
new System.Data.OleDb.OleDbDataAdapter : string * System.Data.OleDb.OleDbConnection -> System.Data.OleDb.OleDbDataAdapter
Public Sub New (selectCommandText As String, selectConnection As OleDbConnection)

Parametry

selectCommandText
String

Ciąg, który jest instrukcją SQL SELECT lub procedurą składowaną, która ma być używana przez SelectCommand właściwość OleDbDataAdapter.

selectConnection
OleDbConnection

Element OleDbConnection reprezentujący połączenie.

Przykłady

Poniższy przykład tworzy obiekt OleDbDataAdapter i ustawia niektóre z jego właściwości.

public static OleDbDataAdapter CreateDataAdapter(
    OleDbConnection connection)
{
    string selectCommand =
        "SELECT CustomerID, CompanyName FROM Customers";
    OleDbDataAdapter adapter =
        new OleDbDataAdapter(selectCommand, connection);

    adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;

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

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

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

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

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

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

    return adapter;
}
Public Function CreateDataAdapter( _
    ByVal connection As OleDbConnection) As OleDbDataAdapter

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

    adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey

    ' Create the commands.
    adapter.InsertCommand = New OleDbCommand( _
        "INSERT INTO Customers (CustomerID, CompanyName) " & _
         "VALUES (?, ?)")

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

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

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

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

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

    Return adapter
End Function

Uwagi

Ta implementacja otwiera OleDbDataAdapter i zamyka OleDbConnection obiekt , jeśli nie jest jeszcze otwarty. Może to być przydatne w aplikacji, która musi wywołać metodę Fill dla co najmniej OleDbDataAdapter dwóch obiektów. Jeśli obiekt OleDbConnection jest już otwarty, musisz jawnie wywołać Close metodę lub usunąć , aby ją zamknąć.

Podczas tworzenia wystąpienia programu OleDbDataAdapternastępujące właściwości odczytu/zapisu są ustawione na następujące wartości początkowe.

Właściwości Wartość początkowa
MissingMappingAction MissingMappingAction.Passthrough
MissingSchemaAction MissingSchemaAction.Add

Wartość jednej z tych właściwości można zmienić za pomocą oddzielnego wywołania właściwości .

Zobacz też

Dotyczy

OleDbDataAdapter(String, String)

Źródło:
OleDbDataAdapter.cs
Źródło:
OleDbDataAdapter.cs
Źródło:
OleDbDataAdapter.cs
Źródło:
OleDbDataAdapter.cs

Inicjuje OleDbDataAdapter nowe wystąpienie klasy za pomocą klasy SelectCommand.

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

Parametry

selectCommandText
String

Ciąg, który jest instrukcją SQL SELECT lub procedurą składowaną, która ma być używana przez SelectCommand właściwość OleDbDataAdapter.

selectConnectionString
String

Parametry połączenia.

Przykłady

Poniższy przykład tworzy obiekt OleDbDataAdapter i ustawia niektóre z jego właściwości.

public static OleDbDataAdapter CreateDataAdapter(
    OleDbConnection connection)
{
    string selectCommand =
        "SELECT CustomerID, CompanyName FROM Customers";
    OleDbDataAdapter adapter =
        new OleDbDataAdapter(selectCommand, connection);

    adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;

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

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

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

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

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

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

    return adapter;
}
Public Function CreateDataAdapter( _
    ByVal connection As OleDbConnection) As OleDbDataAdapter

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

    adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey

    ' Create the commands.
    adapter.InsertCommand = New OleDbCommand( _
        "INSERT INTO Customers (CustomerID, CompanyName) " & _
         "VALUES (?, ?)")

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

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

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

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

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

    Return adapter
End Function

Uwagi

To przeciążenie konstruktora OleDbDataAdapter używa parametru selectConnectionString do ustawienia SelectCommand właściwości . Nie otwiera jednak połączenia. Nadal musisz jawnie otworzyć połączenie.

Podczas tworzenia wystąpienia programu OleDbDataAdapternastępujące właściwości odczytu/zapisu są ustawione na następujące wartości początkowe.

Właściwości Wartość początkowa
MissingMappingAction MissingMappingAction.Passthrough
MissingSchemaAction MissingSchemaAction.Add

Wartość dowolnej z tych właściwości można zmienić za pomocą oddzielnego wywołania właściwości .

Zobacz też

Dotyczy