ADO2.5比ADO2.1新增的兩個(gè)實(shí)用對象

字號:

OFFICE 2000 安裝的數(shù)據(jù)訪問組件為 ADO 2.1
    OFFICE XP 安裝的數(shù)據(jù)訪問組件為 ADO 2.5
    ADO 2.5 比 ADO 2.1 新增的兩個(gè)實(shí)用對象: Record 和 Stream
    一、Records 代表記錄集、文件或文件系統(tǒng)目錄中的一行。使用 Record 對象的一個(gè)例子是連接到一個(gè)URL的絕對或相對路徑,并用 Record 對象管理相對路徑的文件或目錄。 Record 對象中的字段是文件或目錄。下例演示了連接到一個(gè)URL并迭代相對于URL的每一個(gè)文件。
    Sub OpenRecord()
    Dim Record As New ADODB.Record
    Call Record.Open("","URL=http://localhost/",,adOpenIfExists Or adCreateCollection)
    Dim Recordset As New ADODB.Recordset
    Set Recordset = Record.GetChildren
    While Not Recordset.EOF
    Debug.Print Recordset(0)
    Recordset.MoveNext
    Wend
    End Sub
    注:要求本機(jī)安裝了IIS才能測試本例
    二、Stream 與采用它們的大多數(shù)語言中的流類相似。流是定義來管理二進(jìn)制流的類的名稱。 Record 對象管理文件系統(tǒng),流管理單個(gè)文件。下例演示了使用一個(gè) Stream 對象在 Intranet 上讀取文本文件。
    Sub OpenStream()
    Dim Record As New ADODB.Record
    Call Record.Open("Text.txt","URL=http://localhost/access/",,adModeRead)
    Dim Stream As New ADODB.Stream
    Call Stream.Open(Record, adModeRead, adOpenStreamFromRecord)
    Dim Text As String
    Stream.Charset = "ascii"
    Text = Stream.ReadText(adReadAll)
    Debug.Print
    End Sub
    注:要求本機(jī)安裝了IIS才能測試本例,且在虛擬目錄 access 下存在 Text.txt 文件
    即使OFFICE 2000沒有這個(gè)組件,可下載 MDAC 2.5 或更高版本來升級數(shù)據(jù)訪問組件