Data I/O

From Dedupe

Jump to: navigation, search

There are many ways in all languages to read/write to/from files. Please discuss...

Visual Basic

I've started looking at handling data in vb. I don't yet know whether this is efficient, but it certainly seems an easy way: ADO. By using various connection strings you can run SQL commands against most data files.

The following code demonstrates a simple select;

Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
conn.ConnectionString = "Driver={Microsoft Text Driver (*.txt; *.csv)};dbq=c:\dedupe\;Extensions=asc,csv,tab,txt;Extended Properties=text;HDR=YES;FMT=Delimited"
conn.Open
Set rs = conn.Execute("SELECT * FROM iso_countries.csv")
conn.Close
conn.ConnectionString = ""

Text / CSV

The first tests i'm doing are with .csv files. The ADO connection treats a directory on disk as a database and files within that directory (.txt or .csv by default) as tables. Comma-seperated with header row is assumed and column data-types are assumed based on their content. If you wish to specify otherwise, place a file in the database (i.e. directory) named schema.ini adhering to the following format;

[table_name]
Format
ColNameHeader=
Col#=Name Format

[iso_countries.csv]
CSV Delimited
ColNameHeader=True
Col1=Name Text
Col2=Number Text
Col3=Three Text
Col4=Two Text
Col5=ISO Text

Read the full details at microsoft.com

Personal tools
google ads