Recordset in VB6.0

I am fetching data from a database in a recordset using VB6 ... so when retrieving data using Select in SQL, I added a column named Comments , since in the recordset, all table columns + the "Comments" column will be present .. I do not want (nor can I) update any content in the database as I am only "fetching" the data in the database now ...

Now when I submit the selected data for validation, I want to populate the "comments" column with appropriate errors if a particular row in the recordSet is wrong) .... When I do this, I get the error "I am not authorized to do this !! ( update the "Comments" column ....

Now my question is, "How can I solve this problem?" I tried to reproduce this recordset and there, filling in a "comment" (in the replicated one), which in turn showed the same error ... It seems it might be because the duplicate (recordSet) just keeps the properties of the original ...

Can u any1 help solve this problem? Any ways to replicate a recordset (without inheriting its properties) ??????

+1


a source to share


3 answers


I think you are just asking how to make a disabled recordset. To do this, you simply change the position of the cursor in the recordset.



Dim rstTest as ADODB.RecordSet
Set rstTest = New ADODB.RecordSet
With rstTest
   .CursorLocation = adUseClient
   .Open "your sql here", your_connection_object, adOpenStatic, adLockBatchOptimistic, adCmdText
   ' now disconnect it and force the local copy
   .ActiveConnection = Nothing
End With

      

+2


a source


Not exactly what you are looking for, but this is how I do it:



  • Create a class to encapsulate the recordset (Client class for Client table)
  • Add the Comment property to the class, not to recordet
  • Add a Validate method to your class. Ask him to write the Comment property (I'm using the error collection)
  • Read a set of records
  • Parse it into "new client"
  • Validate
  • Check the Comment property (or collecting errors)
+1


a source


You can use the MSDataShape syntax SHAPE..APPEND

to add a new field to your ADO Recordset. Here's a quick example using Jet (MS Access):

Sub ShapeAppendField()

  On Error Resume Next
  Kill Environ$("temp") & "\DropMe.mdb"
  On Error GoTo 0

  Dim cat
  Set cat = CreateObject("ADOX.Catalog")
  With cat
    .Create _
        "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source=" & _
        Environ$("temp") & "\DropMe.mdb"

    Dim jeng
    Set jeng = CreateObject("JRO.JetEngine")
    jeng.RefreshCache .ActiveConnection

    Set .ActiveConnection = Nothing
  End With

  Dim con
  Set con = CreateObject("ADODB.Connection")
  With con
    .ConnectionString = _
        "Provider=MSDataShape;" & _
        "Data Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source=" & _
        Environ$("temp") & "\DropMe.mdb"
    .CursorLocation = 3
    .Open

    .Execute _
    "CREATE TABLE Test (" & _
    "existing_col INTEGER NOT NULL);"
    .Execute _
    "INSERT INTO Test (existing_col)" & _
    " VALUES (1);"

    Dim rs
    Set rs = CreateObject("ADODB.Recordset")
    With rs
      .CursorType = 2
      .LockType = 4
      .Source = _
          "SHAPE {" & _
          " SELECT existing_col" & _
          " FROM Test" & _
          "} APPEND NEW adInteger AS new_col"

      Set .ActiveConnection = con
      .Open
      Set .ActiveConnection = Nothing

      .Fields("new_col").value = 55
      MsgBox .GetString
      .Close

    End With
  End With
End Sub

      

0


a source







All Articles