我有两个不同的数据库,具有相同的表,但当其中一个数据库发生更改时,我需要确切地知道更改了哪些字段。我有一种感觉,我现在使用的解决方案有点低级,也有点慢。我正在做我认为是迭代的事情。
for (int i = 0; i < database1_regCount; i ++)
{
for (int j = 0 ; j< database2_regCount ; j++)
{
if(id_from_Db1 == id_from_Db2)
{
if (col1_from_Db1 != col1_from_Db2)
//do somthing
}
}
}
如果代码有点混乱,很抱歉,我写得真的很快。它基本上是在两个数据库中id匹配的地方逐列进行,并检查它们是否相同。
有没有更快的方法,或者至少有更好的方法呢?
发布于 2015-03-07 20:51:41
使用表上的触发器会有帮助吗?您可以在触发器触发的另一个表中输入所需的信息,然后简单地查询该表的更改...
对于Excel数据库,您可以添加一个宏来检测工作表上的更改,然后记录更改时所需的单元格信息等。
举个例子。
Private Sub Worksheet_Change(ByVal Target As Range)
Dim KeyCells As Range
' The variable KeyCells contains the cells that will
' cause an alert when they are changed.
Set KeyCells = Range("A1:C10")
If Not Application.Intersect(KeyCells, Range(Target.Address)) _
Is Nothing Then
' Display a message when one of the designated cells has been
' changed.
' Place your code here.
MsgBox "Cell " & Target.Address & " has changed."
End If
End Sub
https://stackoverflow.com/questions/28919442
复制