开发者

Have to update datatable and recordset in vb6

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!!!


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜