using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.SqlServerCe; using System.Data.SqlClient; namespace ConsoleApplication2 { class Program { static public void ReadData() { string connStr = "Data Source = TempDB.sdf; Password ="; //if (!File.Exists("DBName.sdf")) { SqlCeConnection conn = new SqlCeConnection(connStr); try { SqlCeEngine engine = new SqlCeEngine(connStr); conn.Open(); SqlCeCommand cmd = conn.CreateCommand(); cmd.CommandText = "SELECT * FROM TestTable WHERE Name = 'Krishna'"; SqlCeDataReader myReader = cmd.ExecuteReader(); while (myReader.Read()) { string strGroup = myReader.GetString(1); int ll = 0; ll++; } } catch (SqlException ex) //catch(Exception) { string strMessage = "\nFailed to Read ***"; strMessage += ex.Message; // Log the exception Console.WriteLine(strMessage); } finally { conn.Close(); } } } static public void WriteData() { string connStr = "Data Source = TempDB.sdf;"; //if (!File.Exists("DBName.sdf")) { SqlCeConnection conn = new SqlCeConnection(connStr); conn.Open(); SqlCeCommand cmd = new SqlCeCommand("INSERT INTO TestTable ([Name], [Group]) Values('Krishna', 'D1')", conn); try { int iRes = cmd.ExecuteNonQuery(); int t = 0; t++; } catch (Exception) { Console.WriteLine("\nFailed to Write\n"); } conn.Close(); } } static void Main(string[] args) { // Write data WriteData(); // Read Data ReadData(); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)