利用实现数据同步功能, 已经完成测试,可以实现.

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("插入数据成功!");
            }
            catch (Exception ex)
            {
                MessageBox.Show("插入数据失败!" + ex.ToString());
            }
        }

       

        //从SQL Server 把数据同步过来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("获取数据成功");
            }
            catch (Exception ex)
            {
                MessageBox.Show("获取数据失败" + ex.ToString());
            }

        }


        // 将修改过的数据同步到SQL Server 数据库中去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("同步数据成功");
            }
            catch (Exception ex)
            {
                MessageBox.Show("同步数据失败" + ex.ToString());         
            }
        }

        private void btn_cancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

      
    }
}

转载于:https://www.cnblogs.com/yqy542006/archive/2007/06/07/775536.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值