using System.Data.SqlClient; using System.Data.Common; string connectionString = "Data Source=myServerAddress;Initial Catalog=myDataBase;User ID=myUsername;Password=myPassword;"; using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); SqlCommand command = new SqlCommand("SELECT IsAdmin FROM Users WHERE Username = 'John'", connection); SqlDataReader reader = command.ExecuteReader(); if (reader.Read()) { bool isAdmin = reader.GetBoolean(0); Console.WriteLine($"Is Admin: {isAdmin}"); } }
using System.Data.OleDb; using System.Data.Common; string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Users\\John\\Documents\\MyDatabase.mdb;"; using (OleDbConnection connection = new OleDbConnection(connectionString)) { connection.Open(); OleDbCommand command = new OleDbCommand("SELECT IsActive FROM Employees WHERE EmployeeID = ?", connection); command.Parameters.AddWithValue("@EmployeeID", 1); OleDbDataReader reader = command.ExecuteReader(); if (reader.Read()) { bool isActive = (bool)reader["IsActive"]; Console.WriteLine($"Is Active: {isActive}"); } }In this example, we are connecting to a Microsoft Access database using the OLE DB provider and executing a SQL query to select the `IsActive` column of the `Employees` table for the employee with the ID of 1. We are then using the `ReadBool()` method to read the boolean value from the data source and storing it in a `bool` variable named `isActive`. Package/Library: System.Data.Common.