OleDbDataAdapter Konstruktor
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Menginisialisasi instans baru kelas OleDbDataAdapter.
Overload
OleDbDataAdapter() |
Menginisialisasi instans baru kelas OleDbDataAdapter. |
OleDbDataAdapter(OleDbCommand) |
Menginisialisasi instans OleDbDataAdapter baru kelas dengan yang ditentukan OleDbCommand sebagai SelectCommand properti . |
OleDbDataAdapter(String, OleDbConnection) |
Menginisialisasi instans OleDbDataAdapter baru kelas dengan SelectCommand. |
OleDbDataAdapter(String, String) |
Menginisialisasi instans OleDbDataAdapter baru kelas dengan SelectCommand. |
OleDbDataAdapter()
- Sumber:
- OleDbDataAdapter.cs
- Sumber:
- OleDbDataAdapter.cs
- Sumber:
- OleDbDataAdapter.cs
Menginisialisasi instans baru kelas OleDbDataAdapter.
public:
OleDbDataAdapter();
public OleDbDataAdapter ();
Public Sub New ()
Contoh
Contoh berikut membuat OleDbDataAdapter dan mengatur beberapa propertinya.
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
Keterangan
Saat Anda membuat instans OleDbDataAdapter, properti baca/tulis berikut diatur ke nilai awal berikut.
Properti | Nilai awal |
---|---|
MissingMappingAction | MissingMappingAction.Passthrough |
MissingSchemaAction | MissingSchemaAction.Add |
Anda dapat mengubah nilai salah satu properti ini melalui panggilan terpisah ke properti .
Lihat juga
Berlaku untuk
OleDbDataAdapter(OleDbCommand)
- Sumber:
- OleDbDataAdapter.cs
- Sumber:
- OleDbDataAdapter.cs
- Sumber:
- OleDbDataAdapter.cs
Menginisialisasi instans OleDbDataAdapter baru kelas dengan yang ditentukan OleDbCommand sebagai SelectCommand properti .
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)
Parameter
- selectCommand
- OleDbCommand
OleDbCommand yang merupakan pernyataan SELECT atau prosedur tersimpan, dan ditetapkan sebagai SelectCommand properti dari OleDbDataAdapter.
Contoh
Contoh berikut membuat OleDbDataAdapter dan mengatur beberapa propertinya.
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
Keterangan
Implementasi OleDbDataAdapter konstruktor ini mengatur SelectCommand properti ke nilai yang ditentukan dalam selectCommand
parameter .
Saat Anda membuat instans OleDbDataAdapter, properti baca/tulis berikut diatur ke nilai awal berikut.
Properti | Nilai awal |
---|---|
MissingMappingAction | MissingMappingAction.Passthrough |
MissingSchemaAction | MissingSchemaAction.Add |
Anda dapat mengubah nilai salah satu properti ini melalui panggilan terpisah ke properti .
Lihat juga
Berlaku untuk
OleDbDataAdapter(String, OleDbConnection)
- Sumber:
- OleDbDataAdapter.cs
- Sumber:
- OleDbDataAdapter.cs
- Sumber:
- OleDbDataAdapter.cs
Menginisialisasi instans OleDbDataAdapter baru kelas dengan 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)
Parameter
- selectCommandText
- String
String yang merupakan pernyataan SQL SELECT atau prosedur tersimpan yang akan digunakan oleh SelectCommand properti dari OleDbDataAdapter.
- selectConnection
- OleDbConnection
Yang OleDbConnection mewakili koneksi.
Contoh
Contoh berikut membuat OleDbDataAdapter dan mengatur beberapa propertinya.
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
Keterangan
Implementasi pembukaan OleDbDataAdapter ini dan menutup OleDbConnection jika belum terbuka. Ini dapat berguna dalam aplikasi yang harus memanggil Fill metode untuk dua objek atau lebih OleDbDataAdapter . OleDbConnection Jika sudah terbuka, Anda harus secara eksplisit memanggil Close atau Membuang untuk menutupnya.
Saat Anda membuat instans OleDbDataAdapter, properti baca/tulis berikut diatur ke nilai awal berikut.
Properti | Nilai awal |
---|---|
MissingMappingAction | MissingMappingAction.Passthrough |
MissingSchemaAction | MissingSchemaAction.Add |
Anda dapat mengubah nilai salah satu properti ini melalui panggilan terpisah ke properti .
Lihat juga
Berlaku untuk
OleDbDataAdapter(String, String)
- Sumber:
- OleDbDataAdapter.cs
- Sumber:
- OleDbDataAdapter.cs
- Sumber:
- OleDbDataAdapter.cs
Menginisialisasi instans OleDbDataAdapter baru kelas dengan 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)
Parameter
- selectCommandText
- String
String yang merupakan pernyataan SQL SELECT atau prosedur tersimpan yang akan digunakan oleh SelectCommand properti dari OleDbDataAdapter.
- selectConnectionString
- String
String koneksi.
Contoh
Contoh berikut membuat OleDbDataAdapter dan mengatur beberapa propertinya.
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
Keterangan
Kelebihan beban OleDbDataAdapter konstruktor ini menggunakan selectConnectionString
parameter untuk mengatur SelectCommand properti . Namun, itu tidak membuka koneksi. Anda masih harus membuka koneksi secara eksplisit.
Saat Anda membuat instans OleDbDataAdapter, properti baca/tulis berikut diatur ke nilai awal berikut.
Properti | Nilai awal |
---|---|
MissingMappingAction | MissingMappingAction.Passthrough |
MissingSchemaAction | MissingSchemaAction.Add |
Anda dapat mengubah nilai salah satu properti ini melalui panggilan terpisah ke properti .