English 中文(简体)
从管理系统接入数据库向另一个系统输入数据而又不改变存取系统的最佳途径是什么?
原标题:What is the best way to import data from MS Access database to another without changing the access db?

我有一个关于访问数据库A(储存60 000多份记录)的表格,我必须输入另一个访问数据库B的表格。

查阅数据库表B从查阅数据库A的表格中储存3 000份记录。

查阅数据库A由另一个方案处理,如果我不必对其作出改动,我就能够打开数据库并获取数据。 我需要从查阅数据库A的表格中输入最新记录和新的记录,以便查阅数据库B。

  • 每天数据库A有100多份新记录和一些更新记录,我需要在当天末输入数据库B。 我需要自动这样做。

  • 新的记录很容易找到,但更新记录如何? 随着更新记录,我需要在数据库B中增加新行,不改变数据库B中的任何行踪。

这样做有没有更好的办法,或许是利用ODBC的链接或其他东西?

Please help me ! Thanks and best regards.

问题回答

-data-and-database-objects-HP2495.aspx> 00516> 查阅这一缩微网页

基本步骤是:

  1. Confirm that the fields and data types in the two tables are compatible e.g. data in fields are transferable;
  2. Attach remote table in Database B from Database A;
  3. Run an append query to transfer the records;
  4. Confirm that it worked e.g. no error messages, correct number of records etc.
  1. In database B, Right click->Link tables.
  2. Choose your database.
  3. Choose your table(s) of interest.

您的数据库B现在与数据库A的数据“链接”。 现在,你可以使用“union”查询或你希望将其与贵国数据库B表格中储存的数据结合起来。 最重要的是,这并不要求对A数据库作任何改动。

为了更新现有的记录,需要比较这两个记录,并在目标数据库中不相同时加以更新。

视所涉领域的数量而定,这可能是复杂的。

Here s code I ve used for that purpose in the past:

  Public Function UpdateTableData(ByVal strSourceTable As String, _
      ByVal strTargetTable As String, ByVal strJoinField As String, _
      ByRef db As DAO.Database, Optional ByVal strExcludeFieldsList As String, _
      Optional strAdditionalCriteria As String) As Boolean
    Dim strUpdate As String
    Dim rsFields As DAO.Recordset
    Dim fld As DAO.Field
    Dim strFieldName As String
    Dim strNZValue As String
    Dim strSet As String
    Dim strWhere As String

    strUpdate = "UPDATE " & strTargetTable & " INNER JOIN " & strSourceTable & " ON " & strTargetTable & "." & strJoinField & " = " & strSourceTable & "." & strJoinField
      if the fields don t have the same names in both tables,
        create a query that aliases the fields to have the names of the
        target table
      if the source table is in a different database and you don t
        want to create a linked table, create a query and specify
        the external database as the source of the table
      alternatively, for strTargetTable, supply a SQL string with
        the external connect string
    Set rsFields = db.OpenRecordset(strSourceTable)
    For Each fld In rsFields.Fields
      strFieldName = fld.Name
      If strFieldName <> strJoinField Or (InStr(", " & strExcludeFieldsList & ",", strFieldName & ",") <> 0) Then
         Select Case fld.Type
           Case dbText, dbMemo
             strNZValue = "  "
           Case Else
             strNZValue = "0"
         End Select
         strSet = " SET " & strTargetTable & "." & strFieldName & " = varZLSToNull(" & strSourceTable & "." & strFieldName & ")"
         strSet = strSet & ", " & strTargetTable & ".Updated = #" & Date & "#"
         strWhere = " WHERE Nz(" & strTargetTable & "." & strFieldName & ", " & strNZValue & ") <> Nz(" & strSourceTable & "." & strFieldName & ", " & strNZValue & ")"
         If db.TableDefs(strTargetTable).Fields(fld.Name).Required Then
            strWhere = strWhere & " AND " & strSourceTable & "." & strFieldName & " Is Not Null"
         End If
         If Len(strAdditionalCriteria) > 0 Then
            strWhere = strWhere & " AND " & strAdditionalCriteria
         End If
         Debug.Print strUpdate & strSet & strWhere
         Debug.Print SQLRun(strUpdate & strSet & strWhere, dbLocal) & " " & strFieldName & " updated."
      End If
    Next fld
    rsFields.Close
    Set rsFields = Nothing
    UpdateTableData = True
  End Function

您可以通过这一职能通过两个表格的名称或两个查询名称。 这使许多灵活性成为可能。 它假设所通过物体的实地名称相同,如果它们的名字相同,你可以提出对田地的询问,以便与另一张表格的相匹配。

这是使用刺.时间的编号一的变式。 基本原则是,它根据各行各有不同价值的最新表格,进行一系列的审调和查询。





相关问题
what is wrong with this mysql code

$db_user="root"; $db_host="localhost"; $db_password="root"; $db_name = "fayer"; $conn = mysqli_connect($db_host,$db_user,$db_password,$db_name) or die ("couldn t connect to server"); // perform query ...

Users asking for denormalized database

I am in the early stages of developing a database-driven system and the largest part of the system revolves around an inheritance type of relationship. There is a parent entity with about 10 columns ...

Easiest way to deal with sample data in Java web apps?

I m writing a Java web app in my free time to learn more about development. I m using the Stripes framework and eventually intend to use hibernate and MySQL For the moment, whilst creating the pages ...

join across databases with nhibernate

I am trying to join two tables that reside in two different databases. Every time, I try to join I get the following error: An association from the table xxx refers to an unmapped class. If the ...

How can I know if such value exists in database? (ADO.NET)

For example, I have a table, and there is a column named Tags . I want to know if value programming exists in this column. How can I do this in ADO.NET? I did this: OleDbCommand cmd = new ...

Convert date to string upon saving a doctrine record

I m trying to migrate one of my PHP projects to Doctrine. I ve never used it before so there are a few things I don t understand. In my current code, I have a class similar to this: class ...

热门标签