设为首页 加入收藏

TOP

SQLServer数据全同步及价值分析[终结版](二)
2014-11-23 22:14:34 来源: 作者: 【 】 浏览:10
Tags:SQLServer 数据 同步 价值 分析 终结
/update source to dest if (setScriptsIndex > 0) { cmd = new SqlCommand("Update " + tableName + " set " + setScripts + " where " + primaryKeyName + "='" + recordsSource[primaryKeyValue][primaryKeyName] + "'", destinationConnector); cmd.ExecuteNonQuery(); } //insert source to dest if (insertScriptsIndex > 0) { cmd = new SqlCommand("insert into " + tableName + " (" + insertKeysScripts + ") values (" + insertValuesScripts + ")", destinationConnector); cmd.ExecuteNonQuery(); } } //after update and insert, the count still not match, means we delete some records in source db, then we also need to delete the records in destination db foreach (var re in recordsDest) { //get the delete record primary key value if (!recordsSource.ContainsKey(re.Key)) { cmd = new SqlCommand("delete from " + tableName + " where " + primaryKeyName + "='" + re.Value[primaryKeyName].ToString() + "'", destinationConnector); cmd.ExecuteNonQuery(); } } // Close objects destinationConnector.Close(); mySqlConn.Close(); }

代码的基础类其他部分请看下列文章:

1. C#同步SQL Server数据库中的数据--数据库同步工具[同步已有的有变化的数据]

2.分析下自己写的SQL Server同步工具的性能和缺陷

3.C#同步SQL Server数据库中的数据--数据库同步工具[同步新数据]

4.C#同步SQL Server数据库Schema
首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇SQLServerDatabase维护计划创建完.. 下一篇sql实现行列转换

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: