The following code is taken from
Using System;
Using System. Collections. Generic;
Using System. ComponentModel;
Using System. Data;
Using System. Drawing;
Using System. Text;
Using System. Windows. Forms;
Using System. Data. SqlClient;
Using System. Data. SqlServerCe;
Using System. IO;
Using System. Xml;
Namespace LocalTest
{
Public partial class Form6: Form
{
String remoteString;
String localString;
SqlCeConnection conn = new SqlCeConnection ("DataSource = Test. sdf ");
Public Form6 ()
{
InitializeComponent ();
}
Private void Form_Load (object sender, EventArgs e)
{
// Conn. ConnectionString = "DataSource = mysdf. sdf ";
RemoteString = "provider = sqloledb; Data Source = 172.18.188.31; Initial Catalog = InfoDB; Persist Security Info = True; User ID = Test; Password = sa ";
LocalString = "DataSource = Test. sdf ";
}
Private void btn_save_Click (object sender, EventArgs e)
{
Try
{
String ls_pcno, ls_pcxh, ls_type, ls_date;
Ls_pcno = tb_no.Text.ToString (). Trim ();
Ls_pcxh = tb_xh.Text.ToString (). Trim ();
Ls_type = tb_type.Text.ToString (). Trim ();
Ls_date = tb_date.Text.ToString (). Trim ();
String ls_ SQL = "insert into pc values ('" + ls_pcno + "', '" + ls_pcxh + "', '" + ls_type + "', '"+ ls_date + "')";
MessageBox. Show (ls_ SQL );
SqlCeCommand cmd = new SqlCeCommand (ls_ SQL );
Conn. Open ();
Cmd. Connection = conn;
Cmd. ExecuteNonQuery ();
Conn. Close ();
MessageBox. Show ("data inserted successfully! ");
}
Catch (Exception ex)
{
MessageBox. Show ("failed to insert data! "+ Ex. ToString ());
}
}
// Synchronize data from SQL Server to PULL
Private void btn_rec_Click (object sender, EventArgs e)
{
Try
{
SqlCeRemoteDataAccess rda = new SqlCeRemoteDataAccess ();
Rda. LocalConnectionString = localString;
Rda. InternetUrl = "http: // 172.18.188.31/test/sqlcesa30.dll ";
Rda. Pull ("pcinfo", "select * from pc", remoteString, RdaTrackOption. TrackingOn, "ErrorList ");
MessageBox. Show ("data retrieved ");
}
Catch (Exception ex)
{
MessageBox. Show ("failed to get data" + ex. ToString ());
}
}
// Synchronize the modified data to the SQL Server database for PUSH
Private void btn_send_Click (object sender, EventArgs e)
{
Try
{
SqlCeRemoteDataAccess rda = new SqlCeRemoteDataAccess ();
Rda. LocalConnectionString = localString;
Rda. InternetUrl = "http: // 172.18.188.31/test/sqlcesa30.dll ";
Rda. Push ("pcinfo", remoteString, RdaBatchOption. BatchingOn );
MessageBox. Show ("Data Synchronization succeeded ");
}
Catch (Exception ex)
{
MessageBox. Show ("failed to synchronize data" + ex. ToString ());
}
}
Private void btn_cancel_Click (object sender, EventArgs e)
{
This. Close ();
}
}
}