以编程方式将字段绑定到临时记录集字段 [英] Bind field to temporary recordset field programmatically

查看:22
本文介绍了以编程方式将字段绑定到临时记录集字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试显示以编程方式创建的记录集.但是我在将控制源绑定到记录集字段时遇到了问题.

I'm trying to display a recordset that is created programmatically. But I'm having problems binding the controlsource to the recordset fields.

以下代码在 FirstField 文本框中输出#Error".

The following code outputs "#Error" in the FirstField textbox.

Option Compare Database
Option Explicit

Private Sub Form_Load()
    Dim rs As ADODB.Recordset
    Set rs = New ADODB.Recordset

    With rs.Fields
        .Append "A", adInteger
        .Append "B", adInteger
        .Append "C", adInteger
    End With

    rs.Open

    With rs
      .AddNew
        ![a] = 1
        ![b] = 1
        ![c] = 1
      .Update
    End With

    rs.Clone

    Set Me.Recordset = rs
    Me.FirstField.ControlSource = rs.Fields(0).Name 'outputs #Error in FirstField
End Sub

非常感谢帮助!

我有一个数据库,用于表示停车场中已使用的停车位.A、B、C 是位置坐标,每个坐标都有一个验证规则集,因此它们不能超过它们的限制.现在我想显示所有可用的停车位.所以我想我会创建一个包含所有停车位的假"数据库,然后做一个查询,我只显示假数据库中的位置不在已用停车位"数据库中的位置.

I have a database which represent used parking spaces in a parking lot. A,B,C are position coordinates each of these have a validation rule set so they cannot exceed their limits. Now I want to display all available parking spaces. So I figured I'd create a "fake" database with all parking spaces and then do a query-thing where I only display entires from the fake database where the position is not in the "used parking space" database.

创建一个只有位置的数据库对我来说似乎很愚蠢,用所有停车位填充已用停车位"数据库,然后添加一个已用的布尔字段似乎也是一个坏主意.

Creating a database with only the positions seemed silly to me and populating the "used parking space" database with all parking spaces and then adding a used boolean field also seemed like a bad idea.

我欢迎就如何以更好的方式解决这个问题提出意见.

I welcome input on how I could solve this in a better way.

感谢您抽出宝贵时间.

推荐答案

从您的评论中,我看到您打算重新设计,这对我来说似乎是个好主意.尽管如此,如果您想进一步试验与 ADO 断开连接的表单记录集,请在 .Open 之前包含 .LockType.

From your comment, I see you intend to redesign, which seems like a good idea to me. Despite that, if you want to experiment further with an ADO disconnected recordset for a form, include .LockType before .Open.

rs.LockType = adLockPessimistic
rs.Open

通过这一更改,并丢弃 rs.Clone 行,您的 Form_Load 代码可用于我的测试表单.

With that change, and discarding the rs.Clone line, your Form_Load code works on my test form.

有关此主题的更多详细信息,请参阅数据库期刊中的这篇文章:创建内存中 ADO 记录集.

See this article from Database Journal for more details on this subject: Create In-Memory ADO Recordsets.

这篇关于以编程方式将字段绑定到临时记录集字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆