using System.Data.SqlClient; using System.Data; public class ExampleDbManager { private readonly string connectionString; public ExampleDbManager(string connectionString) { this.connectionString = connectionString; } public DataTable GetCustomers() { using (var connection = new SqlConnection(connectionString)) using (var command = new SqlCommand("SELECT * FROM Customers", connection)) { connection.Open(); var adapter = new SqlDataAdapter(command); var table = new DataTable(); adapter.Fill(table); return table; } } }
using System.Data.OleDb; using System.Data; public class ExampleDbManager { private readonly string connectionString; public ExampleDbManager(string connectionString) { this.connectionString = connectionString; } public int InsertCustomer(string firstName, string lastName, string email) { using (var connection = new OleDbConnection(connectionString)) using (var command = new OleDbCommand("INSERT INTO Customers (FirstName, LastName, Email) VALUES (?, ?, ?)", connection)) { command.Parameters.AddWithValue("@firstname", firstName); command.Parameters.AddWithValue("@lastname", lastName); command.Parameters.AddWithValue("@email", email); connection.Open(); return command.ExecuteNonQuery(); } } }This example shows how you can use the `DbManager` class to insert a new customer record into a database. We use a `OleDbConnection` object (from the System.Data.OleDb namespace) to connect to the database, and a `OleDbCommand` object to execute the insert query. We also use parameterized queries to prevent SQL injection attacks. Finally, the `ExecuteNonQuery()` method is called to execute the query and return the number of rows affected. The library/packages used in these examples are part of the C# ADO.NET library that comes built-in with the .NET Framework. There are no additional external packages required.