必须在vb6中更新数据表和记录集

发布于 2024-10-23 18:59:26 字数 148 浏览 4 评论 0原文

我目前在带有 adodb 连接的表单上使用数据表,运行良好。但是它不会检测到更新的更改。我想放置 2 个记录集来比较这两个记录集,因为我需要列名称并更改旧的和新的列信息,因此我在记录集中放置了一列。

如果有人可以告诉我如何进行循环或完成此任务所需的任何内容,请!!!

I am currently using a datable on a form with an adodb connection which runs fine. However it does not detect changes to update. I want to put 2 recordsets to compare the two as I need the column name and changed column info the old and the new, so I put a column in the recordset.

If someone could shoe me how to do the loop or whatever is needed to get this done please!!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

兲鉂ぱ嘚淚 2024-10-30 18:59:26

我不确定是否完全解决了您的问题...如果您想向记录集中添加一列,该列只能在您的代码中更新(即无法写回数据库,因为它确实不是来自数据库)那么您可以使用 MsDataShape OLE DB 提供程序及其 SHAPE...APPEND 语法,例如

Sub MSDataShape_AddNewCol()

  Dim rs As ADODB.Recordset
  Set rs = CreateObject("ADODB.Recordset")
  With rs
    .ActiveConnection = _
        "Provider=MSDataShape;" & _
        "Data Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source=C:\Tempo\My_Access_DB.mdb"

    .Source = _
        "SHAPE {" & _
        " SELECT ExistingField" & _
        " FROM ExistingTable" & _
        " ORDER BY ExistingField" & _
        "} APPEND NEW adNumeric(5, 4) AS NewField"

    .LockType = adLockBatchOptimistic

    .Open

    Dim i As Long
    For i = 0 To .RecordCount - 1
      .Fields("NewField").Value = Round(.Fields("ExistingField").Value, 4)
      .MoveNext
    Next

    rs.Save "C:\rs.xml", adPersistXML  ' 

  End With
End Sub

I'm not sure if addresses your problem exactly... if you want to add a column to a recordset that can be updated in your code only (i.e. cannot be written back to the database because it did not come from the database) then you can use the MsDataShape OLE DB provider with its SHAPE...APPEND syntax e.g.

Sub MSDataShape_AddNewCol()

  Dim rs As ADODB.Recordset
  Set rs = CreateObject("ADODB.Recordset")
  With rs
    .ActiveConnection = _
        "Provider=MSDataShape;" & _
        "Data Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source=C:\Tempo\My_Access_DB.mdb"

    .Source = _
        "SHAPE {" & _
        " SELECT ExistingField" & _
        " FROM ExistingTable" & _
        " ORDER BY ExistingField" & _
        "} APPEND NEW adNumeric(5, 4) AS NewField"

    .LockType = adLockBatchOptimistic

    .Open

    Dim i As Long
    For i = 0 To .RecordCount - 1
      .Fields("NewField").Value = Round(.Fields("ExistingField").Value, 4)
      .MoveNext
    Next

    rs.Save "C:\rs.xml", adPersistXML  ' 

  End With
End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文