|
你这可真是叫骑驴找驴:)
有空学点ADO的基本理论吧:封装在ADO中的数据驱动如下:
"MSDASQL" Microsoft OLE DB Provider for ODBC Data Provider
"SQLOLEDB" Microsoft OLE DB Provider for SQL Server Data Provider
"MSDataShape" Microsoft Data Shaping Service for OLE DB Service Provider
(內建) Microsoft Cursor Service for OLE DB Service Provider(Service Componet)
说明:若不指明使用何种Provider,ADO使用默认的MSDASQL,即Microsoft OLE DB Provider for ODBC。
下面是一小段利用DATAShape的例句(摘自俺的老笔记,出处我忘了):
Dim con As ADODB.Connection
Dim rstPubs As ADODB.Recordset
Dim rstTitles As ADODB.Recordset
Dim sShape As String
Set con = New ADODB.Connection
Set rstPubs = New ADODB.Recordset
con.Provider = "MSDataShape" '这就是你要的
con.Open "Data Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=Biblio.mdb;"
sShape = "SHAPE {SELECT Name, PubID " _
& " FROM Publishers} " _
& " APPEND ({SELECT Title, PubID " _
& " FROM Titles} " _
& " As PubTitles " _
& " RELATE PubID TO PubID) "
rstPubs.Open sShape, con
Do Until (rstPubs.EOF)
Debug.Print rstPubs!Name
Set rstTitles = rstPubs("ubTitles").Value
Do Until (rstTitles.EOF)
Debug.Print " " & rstTitles!Title
rstTitles.MoveNext
Loop
rstPubs.MoveNext
Loop
rstPubs.Close
con.Close
Set rstPubs = Nothing
Set con = Nothing
Biblio.mdb是安装VB的时候装入的例子库。这里用到了其中的两个表:Publishers、Titles。以相同字段PubID做成一对多联接。还可以照此例嵌套更多的子表(SQL语句)。
DataShape最大的特点是允许你聚合多个SQL语句,构造出层次型的记录集。在层次型记录集中,单个字段能够指向整个子记录集。
至于怎么用它来实现你要求的效果你自己去试验吧。
|
|