OleDbCommand 是用于在 ASP.NET 中與 OleDb 數據源進行交互的對象。以下是 OleDbCommand 的常用用法:
OleDbCommand command = new OleDbCommand();
command.CommandText = "SELECT * FROM TableName";
command.Connection = connection; // connection 是一個 OleDbConnection 對象
OleDbDataReader reader = command.ExecuteReader();
while (reader.Read())
{
// 處理每一行的數據
}
reader.Close();
int rowsAffected = command.ExecuteNonQuery();
command.CommandText = "SELECT * FROM TableName WHERE ColumnName = ?";
command.Parameters.AddWithValue("ColumnName", columnValue);
OleDbTransaction transaction = connection.BeginTransaction();
command.Transaction = transaction;
try
{
// 執(zhí)行多個 OleDbCommand 對象
transaction.Commit();
}
catch
{
transaction.Rollback();
}
finally
{
transaction.Dispose();
}
這些是 OleDbCommand 的基本用法,你可以根據具體的需求進行調整和擴展。