Access SQL Mobile from Desktop Application (.NET)
Introduction
Accessing the Mobile DB (SQL CE/ SQL Mobile) from desktop application. Synchronization of Desktop/Server DB and SQL Mobile
Background
Following code snippets show how to access SQL CE of a PPC 2003 or Windows Mobile DB from Desktop Application when device is craddled and connected through Microsoft Active Sync.
The code uses the Microsoft.SqlServerCe.Client.dll instead of System.Data.SqlServerCe.dll
The code
Code: C#.NET
Code:
//import namesspace
using Microsoft.SqlServerCe.Client;
//Connection string
string conStr = "Data Source = Mobile Device\My Documents\MySQLCeDB.sdf;";
//Create Connection
SqlCeConnection sqlceCon = new SqlCeConnection(conStr);
//open connection
sqlceCon.Open();
//Create CommandObject
SqlCeCommand sqlceCmd = new SqlCeCommand();
sqlceCmd.CommandType = CommandType.Text;
sqlceCmd.CommandText = "Select count(*) from myTable"; //say Mytable is the source table
sqlceCmd .Connection = sqlceCon;
//Execute Query
int rowCount = sqlceCmd.ExecuteNonQuery();
//Close Connection
sqlceCon.Close();
Thanks :D
|