using System.Data.SqlServerCe; // create a new connection SqlCeConnection conn = new SqlCeConnection("Data Source=database.sdf"); // open the connection conn.Open();
using System.Data.SqlServerCe; // create a new connection SqlCeConnection conn = new SqlCeConnection("Data Source=database.sdf"); // open the connection conn.Open(); // create a command SqlCeCommand cmd = new SqlCeCommand("SELECT name, age FROM people", conn); // execute the query and retrieve data SqlCeDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { string name = reader.GetString(0); int age = reader.GetInt32(1); Console.WriteLine("{0} is {1} years old", name, age); } // close the connection conn.Close();This code creates a new SqlCeConnection object and opens the connection. It then creates a SqlCeCommand object with a SELECT statement and executes the query using SqlCeDataReader. The code loops through the data returned from the query and displays it to the console. Overall, SqlCeConnection is a useful class in C# for connecting to SQL Server Compact Edition databases and performing queries.