OleDbDataAdapter 构造函数

定义

初始化 OleDbDataAdapter 类的新实例。

重载

OleDbDataAdapter()

初始化 OleDbDataAdapter 类的新实例。

OleDbDataAdapter(OleDbCommand)

初始化 OleDbDataAdapter 类的新实例,用指定的 OleDbCommand 作为 SelectCommand 的属性。

OleDbDataAdapter(String, OleDbConnection)

OleDbDataAdapter 初始化 SelectCommand 类的新实例。

OleDbDataAdapter(String, String)

OleDbDataAdapter 初始化 SelectCommand 类的新实例。

OleDbDataAdapter()

Source:
OleDbDataAdapter.cs
Source:
OleDbDataAdapter.cs

初始化 OleDbDataAdapter 类的新实例。

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

示例

以下示例创建 并 OleDbDataAdapter 设置其一些属性。

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

注解

创建 实例 OleDbDataAdapter时,以下读/写属性设置为以下初始值。

属性 初始值
MissingMappingAction MissingMappingAction.Passthrough
MissingSchemaAction MissingSchemaAction.Add

可以通过单独调用 属性来更改其中任何属性的值。

另请参阅

适用于

OleDbDataAdapter(OleDbCommand)

Source:
OleDbDataAdapter.cs
Source:
OleDbDataAdapter.cs

初始化 OleDbDataAdapter 类的新实例,用指定的 OleDbCommand 作为 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)

参数

selectCommand
OleDbCommand

OleDbCommand,它是 SELECT 语句或存储过程,被设置为 SelectCommandOleDbDataAdapter 属性。

示例

以下示例创建 并 OleDbDataAdapter 设置其一些属性。

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

注解

构造函数的 OleDbDataAdapter 此实现将 SelectCommand 属性设置为 参数中指定的 selectCommand 值。

创建 实例 OleDbDataAdapter时,以下读/写属性设置为以下初始值。

属性 初始值
MissingMappingAction MissingMappingAction.Passthrough
MissingSchemaAction MissingSchemaAction.Add

可以通过单独调用 属性来更改其中任何属性的值。

另请参阅

适用于

OleDbDataAdapter(String, OleDbConnection)

Source:
OleDbDataAdapter.cs
Source:
OleDbDataAdapter.cs

OleDbDataAdapter 初始化 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)

参数

selectCommandText
String

一个字符串,它是 SQL SELECT 语句或将由 SelectCommandOleDbDataAdapter 属性使用的存储过程。

selectConnection
OleDbConnection

表示连接的 OleDbConnection

示例

以下示例创建 并 OleDbDataAdapter 设置其一些属性。

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

注解

如果 尚未打开,则 的 OleDbDataAdapter 此实现会 OleDbConnection 打开并关闭 。 这在必须为两个或更多OleDbDataAdapter对象调用 Fill 方法的应用程序中非常有用。 OleDbConnection如果 已打开,则必须显式调用 CloseDispose 以关闭它。

创建 实例 OleDbDataAdapter时,以下读/写属性设置为以下初始值。

属性 初始值
MissingMappingAction MissingMappingAction.Passthrough
MissingSchemaAction MissingSchemaAction.Add

可以通过单独调用 属性来更改其中任一属性的值。

另请参阅

适用于

OleDbDataAdapter(String, String)

Source:
OleDbDataAdapter.cs
Source:
OleDbDataAdapter.cs

OleDbDataAdapter 初始化 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)

参数

selectCommandText
String

一个字符串,它是 SQL SELECT 语句或将由 SelectCommandOleDbDataAdapter 属性使用的存储过程。

selectConnectionString
String

连接字符串。

示例

以下示例创建 并 OleDbDataAdapter 设置其一些属性。

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

注解

构造函数的 OleDbDataAdapter 此重载使用 selectConnectionString 参数来设置 SelectCommand 属性。 但是,它不会打开连接。 仍必须显式打开连接。

创建 实例 OleDbDataAdapter时,以下读/写属性设置为以下初始值。

属性 初始值
MissingMappingAction MissingMappingAction.Passthrough
MissingSchemaAction MissingSchemaAction.Add

可以通过单独调用 属性来更改其中任何属性的值。

另请参阅

适用于