privatevoidIncrementalSyncUpdate(stringfromConn,stringtoConn,Dictionary
{
varsw=newStopwatch();
using(varconn=newSqlConnection(fromConn))
{
if(conn.State!=ConnectionState.Open)conn.Open();
using(varcmd=newSqlCommand())
{
try
{
foreach(variteminsqlList)
{
varsql=item.Value;
vartableName=item.Key;
sw.Restart();
cmd.CommandText=sql;
cmd.CommandType=CommandType.Text;
cmd.Connection=conn;
DataTabledt=newDataTable();
SqlDataAdaptersda=newSqlDataAdapter(cmd);
sda.Fill(dt);
if(dt.Rows.Count==0)continue;//如果没有新增数据,跳过
foreach(DataRowrowindt.Rows)
{
row.SetModified();
}
intupdateCount=0;
using(varTmpConn=newSqlConnection(toConn))
{
if(TmpConn.State!=ConnectionState.Open)TmpConn.Open();
using(vartmpCmd=newSqlCommand())
{
tmpCmd.CommandText="select*fromMeb_"+tableName;
tmpCmd.CommandType=CommandType.Text;
tmpCmd.Connection=TmpConn;
SqlDataAdaptertmpSda=newSqlDataAdapter(tmpCmd);
SqlCommandBuilderscb=newSqlCommandBuilder(tmpSda);
tmpSda.UpdateCommand=scb.GetUpdateCommand();
updateCount=tmpSda.Update(dt);
}
}
sw.Stop();
Console.WriteLine("增量同步数据更新完成,表名:{0},数据{1}条,耗时{2}秒",tableName,updateCount,sw.Elapsed.TotalSeconds);
}
}
catch(Exceptione)
{
Console.WriteLine("增量同步数据同步更新失败,"+e.ToString());
}
}
}
}