VB6.0中的记录集

发布于 2024-07-21 05:08:40 字数 448 浏览 11 评论 0原文

我正在使用 VB6 从记录集中的数据库检索数据...因此,在使用 SQL 中的 Select 检索数据时,我添加了一个名为 Comments 的列,以便在记录集中,表的所有列+“注释”列都会出现...我不想(而且我不能)更新数据库中的任何内容,因为我只是现在从数据库“获取”数据...

现在,当我传递获取的数据进行验证时,如果记录集中的特定行是错误的,我想用相应的错误填充“注释”列)...当我这样做我收到一条错误消息“我无权这样做!!(更新‘评论’栏”……

现在我的问题是“我可以通过什么方式解决这个问题???”..我尝试复制此记录集,现在填充了“注释”列(在复制的记录集中),这又显示了相同的错误...看来这可能是因为重复的记录集(记录集)只保留了记录集的属性原来的...

你能帮忙解决这个问题吗??? 有什么方法可以复制记录集(不继承其属性)??????

I'm retrieving Data from a Database in a record set using VB6... so while retrieving data using Select in SQL I added a column called Comments along wit it so that in the recordset, all the columns of the table+'Comments' column would be present... I don't want to(and also I cannot) update any contents in the database as i'm only 'fetching' data frm the database now...

Now when i pass the fetched data for validation, I want to fill the 'comments' Column with the respective errors if the particular row in the recordSet is erroneous).... When i do that i get an error saying "I'm not authorized to do that!!(to update the 'Comments' Column"....

Now My Question is "In what way i can solve this problem???".. I tried to replicate this recordset and there by now filling the 'comments'column (in the replicated one) which in turn showed the same error... It seems this could be because the duplicate one(recordSet) just retains the properties of the original one...

Can u any1 help how to solve this???? Any ways to replicate the recordset(without inheriting its properties something)??????

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

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

发布评论

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

评论(3

扭转时空 2024-07-28 05:08:40

我认为您只是问如何执行断开连接的记录集。
为此,您只需更改记录集的光标位置即可。

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

I think you are just asking how to do a disconnected recordset.
For that you just change the cursor location of 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
始于初秋 2024-07-28 05:08:40

不完全是您正在寻找的,但这就是我这样做的方法:

  1. 创建一个类来封装记录集(“客户”表的“客户”类)
  2. 将您的 Comment 属性添加到该类而不是记录集中
  3. 将 Validate 方法添加到你的班。 将其写入您的 Comment 属性(我使用 Errors 集合)
  4. 读取记录集
  5. 将其解析为“新客户”
  6. 验证
  7. 检查 Comment 属性(或 Errors 集合)

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

  1. Create a class to encapsulate the recordset ('Customer' class for 'Customer' table)
  2. Add your Comment property to the class and not to recordset
  3. Add a Validate method to your class. Have it write to your Comment property (I use an Errors Collection)
  4. Read the recordset
  5. Parse it into a "new Customer"
  6. Validate
  7. Check the Comment property (or the Errors Collection)
别挽留 2024-07-28 05:08:40

您可以使用 MSDataShape 及其 SHAPE..APPEND 语法将新字段附加到 ADO 记录集。 下面是一个使用 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

You can use the MSDataShape with its SHAPE..APPEND syntax to append a new Field to an ADO Recordset. Here's a quick example using Jet (a.k.a. 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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文