Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem in Reading CSV file

Status
Not open for further replies.

tumtoo10

Programmer
Dec 10, 2001
40
0
0
US
I have a csv file and wish to to load the data into sql server table selectively. I don't want to use the Data transformation service of SQL Server.
Iam using the following code to open the csv file

Dim db As Database
Set db = OpenDatabase("C:\PartUpdate.csv")
but it says unrecognised database format. how can i overcome it.
Any other solutions for the above problem.
 
As CSV format is a Excel file
try to export it in access or use
stream objects to read it from file and pass the data into desired position
 
Let db define you SQL Server database.

Dim db As Database
Dim strInput As String
Dim varInput As Variant

Open "C:\PartUpdate.csv" For Input As #1
Do While Not EOF(1)
Line Input #1, strInput
varInput = Split(strInput, ",")
' varInput(0) contains the first field - save to DB
' varInput(1) contains the second field - save to DB
' Save/Add all fields to DB
Loop
Close #1
 
using ado you can open it directly. I would advise you to go and read up on data access techniques first. Try the help file and microsoft site. Peter Meachem
peter@accuflight.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top