VBGood网站全文搜索 Google

首页 - 经验之谈 - 正确的把text文件读入ADO对象中
发表评论(0)作者:不详, 平台:VB6.0+Win98, 阅读:12196, 日期:2001-01-10
Accurately read text files into ADO recordsets
Often, you may have cause to read a comma-delimited, or some other
form of delimitation, into an ADO recordset. However, if your text
file doesn注释:t contain header information, you may encounter odd
behavior in which ADO uses data in the first record as the recordset注释:s
field names.

This glitch results because, by default, ADO assumes that each text
file will contain headers on the first row. So how do you indicate
otherwise? One hint can be found in the connection string generated by
Visual Basic when it connects to a text file, as seen here:

connCSV.Open "Provider=Microsoft.Jet.OLEDB.4.0;" _
        & "Data Source=" & App.Path & ";" _
        & "Extended Properties=注释:text;FMT=Delimited注释:"

As you can see, the connection string contains a section called
Extended Properties, which indicates a delimited text file. By adding
a third argument to this section, we can tell ADO that the file doesn注释:t
contain headers. The argument named HDR takes YES or NO as its sole
value. With this extra argument in place, the completed connection
string looks like this:

connCSV.Open "Provider=Microsoft.Jet" _
        & ".OLEDB.4.0;Data Source=" & App.Path _
        & ";Extended Properties=注释:text;HDR=NO;" _
        & "FMT=Delimited注释:"