private static string connectionString = "Data Source=MyData.sdf"; using (SqlCeConnection connection = new SqlCeConnection(connectionString)) { connection.Open(); SqlCeCommand command = new SqlCeCommand("SELECT COUNT(*) FROM Employee", connection); int count = (int)command.ExecuteScalar(); Console.WriteLine("Total number of employees: " + count); connection.Close(); }
private static string connectionString = "Data Source=MyData.sdf"; using (SqlCeConnection connection = new SqlCeConnection(connectionString)) { connection.Open(); int productId = 1; // example product ID SqlCeCommand command = new SqlCeCommand("SELECT Price FROM Product WHERE ProductID = @ProductID", connection); command.Parameters.AddWithValue("@ProductID", productId); decimal price = (decimal)command.ExecuteScalar(); Console.WriteLine("Price of product " + productId + ": $" + price); connection.Close(); }Both examples use the 'System.Data.SqlServerCe' package library, which is used to connect to and interact with SQL Server Compact databases.