简体   繁体   English

MS-Access:是否可以连续形式显示“虚拟”行?

[英]MS-Access: is it possible to display 'virtual' rows in a continuous form?

I am looking for a method to display virtual rows in an MS Access application, that is, rows that don't actually exist in any table, but only in memory. 我正在寻找一种在MS Access应用程序中显示虚拟行的方法,即虚拟行实际上不存在于任何表中,而仅存在于内存中。

I could probably create a temporary table as I need it, fill it with my 'virtual row' values and then display the temporary table's content in the continuous form. 我可能会根据需要创建一个临时表,用“虚拟行”值填充它,然后以连续形式显示临时表的内容。 Yet, if possible, I'd like to such a thing without using any temporary tables. 但是,如果可能的话,我想在不使用任何临时表的情况下进行此类操作。

Thanks for any help 谢谢你的帮助

Rene 雷内

edit : When I refer to a 'row in memory', I mean to say that I have a few variables (possibly stored in an array of arrays) that I want to display on the gui/form the same way as rows stored in a table. 编辑 :当我指的是“行在内存中”时,我的意思是说我有一些变量(可能存储在数组数组中),希望以与存储在行中的行相同的方式在gui / form上显示表。

ADO allows you to create disconnected recordsets, and an ADO recordset can be assigned as the form's recordset, so that sounds like the way to go. ADO允许您创建断开连接的记录集,并且可以将ADO记录集分配为表单的记录集,因此听起来很像。

But I'd caution that I don't use ADO for any functionality that is provided by DAO, and while DAO has nothing like disconnected recordsets (though for some operations you can use a transaction to fake it), I've never needed them myself, so I'm really reporting second-hand information. 但是我要提醒我,不要将ADO用于DAO提供的任何功能,尽管DAO与断开记录集没有什么不同(尽管对于某些操作,您可以使用事务来伪造它),但我从不需要它们我自己,所以我实际上是在报告二手信息。

However, this is likely a profitable thing for you to investigate, at least insofar as I understand your question. 但是,至少在我了解您的问题的范围内,这对于您进行调查可能是一件有益的事情。

You could add entries to a list box with multiple columns. 您可以将条目添加到具有多个列的列表框中。 Not exactly a continuous form but close. 不完全是连续形式,而是紧密的形式。 Ensure the Row Source Type of the list box is Value List. 确保列表框的“行源类型”为“值列表”。

Me.SomeListBox.RowSource = ""
Me.SomeListBox.AddItem "record1;field2;field3"
Me.SomeListBox.AddItem "record2;field2;field3"

UNION allows you to include virtual rows and virtual fields (columns) can be defined by including: UNION允许您包含虚拟行,并且可以通过以下方式定义虚拟字段(列):

data As fieldname 数据作为字段名

FROM can be any table or query in the database, but it must contain at least one row otherwise you'll get an zero-row result set. FROM可以是数据库中的任何表或查询,但是它必须至少包含一行,否则您将获得零行结果集。

So: 所以:

SELECT -1 As ID, True As Virtual, "All" As Stuff FROM Table1
UNION
SELECT 0 As ID, True As Virtual, "None" As Stuff FROM Table1

You do not have to include any real rows, but you can: 您不必包括任何实际的行,但是您可以:

UNION 
SELECT  ID, False As Virtual, Stuff FROM Table1

This method is often used to add "All" or "None" to listboxes or comboboxes. 此方法通常用于将“全部”或“无”添加到列表框或组合框。

While you can do this using UNION : 虽然可以使用UNION进行此操作:

SELECT 0 AS ID, True AS Virtual, 'None' AS Stuff 
  FROM Table1
UNION 
SELECT ID, False, Stuff 
  FROM Table1;
UNION
SELECT -1, True, 'All'
  FROM Table1;

...its probably better to do this using UNION ALL with the DISTINCT keyword: ...最好使用UNION ALLDISTINCT关键字来做到这一点:

SELECT DISTINCT 0 AS ID, True AS Virtual, 'None' AS Stuff 
  FROM Table1
UNION ALL
SELECT ID, False, Stuff 
  FROM Table1;
ORDER BY ID
UNION ALL
SELECT DISTINCT -1, True, 'All'
  FROM Table1;

Why prefer UNION ALL ? 为什么选择UNION ALL UNION preforms an implicit sort on the data, which you may not want; UNION对数据执行隐式排序,这可能是您不想要的。 if you do use an explicit sort then use one! 如果确实使用显式排序,则使用一种! (As the documentation will tell you, an implicit sort is not guaranteed so don't rely on it.) (正如文档会告诉您的那样,不能保证隐式排序,所以请不要依赖它。)

In order to performs the sort, only the first 255 characters of MEMO data will be considered and in extremis can lead to whole rows being removed from the resultset :( 为了执行排序,将仅考虑MEMO数据的前255个字符,并且在极端情况下会导致从结果集中删除整行:(

The implicit sort for UNION also has a relatively huge impact on performance: I tested using a 100K row table and the UNION approach took 21 seconds, while the UNION ALL took only 3 seconds. UNION的隐式排序对性能也有相对较大的影响:我使用100K行表进行了测试, UNION方法花费了21秒,而UNION ALL仅花费了3秒。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM