|
-
Mar 18th, 2003, 08:51 AM
#1
Thread Starter
New Member
How to read a file using ADO
How do I read a *.csv file using ADO so I can import it into a table.
Thanks,
Steve
-
Mar 18th, 2003, 11:06 AM
#2
Hyperactive Member
You woudn't read the file using ado here is an example of what you want (I run a stored procedure to load it but you could just run the sql
lFileNum = FreeFile()
Open txtFileName.Text For Input As #lFileNum
Do Until EOF(lFileNum)
Line Input #lFileNum, sRecord
lRow = lRow + 1
sValues = Split(sRecord, "|")
sKitPartNo = sValues(0)
sStockroomTransmitAs = sValues(1)
sDescription = sValues(2)
.Clear
.AddParameter "@vkit_part_no", adParamInput, adVarChar, 20, sKitPartNo
.AddParameter "@vdescription", adParamInput, adVarChar, 100, Trim(sDescription)
.AddParameter "@vstockroom_transmit_as", adParamInput, adVarChar, 3, Trim(sStockroomTransmitAs)
If Not (.ExecuteSP("spm_import_kit", adoImport)) Then
Screen.MousePointer = vbDefault
MsgBox "An error occurred importing the Kits." & vbCrLf & gobjSQL.LastError, vbCritical
GoTo end_cmdImport_Click
End If
Loop
Close #lFileNum
-
Mar 18th, 2003, 11:30 AM
#3
To open a CSV file using ADO you can use the Jet oledb provider. You need to set some extended properties. Here is a sample.
VB Code:
Dim objDB As ADODB.Connection
Dim objRS As ADODB.Recordset
Set objDB = New ADODB.Connection
objDB.Open "provider=microsoft.jet.oledb.4.0;data source=C:\Projects;" & _
"Extended Properties='text;HDR=NO;FMT=Delimited'"
Set objRS = New ADODB.Recordset
objRS.Open "Select * From Testing.txt", objDB, adOpenStatic, adReadOnly, adCmdText
Do
'... Processing
objRS.MoveNext
Loop Until objRS.Eof
objRS.Close
objDB.Close
Set objDB = Nothing
HOWTO: Open Delimited Text Files Using the Jet Provider's Text IIsam
If you are interested - to open fixed length files you need to indicate the fields via a schema ini file. How to Create a Schema.ini File Programmatically
-
Mar 25th, 2003, 07:34 AM
#4
Lively Member
How to read a file using ADO (WHERE)
How I use WHERE when I read a file using ADO?
My fields are separeted with ;
Thanks and sorry about my bad engish.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|