Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old February 13th, 2006, 03:25 AM
DOLL DOLL is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2006
Posts: 32 DOLL User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 50 m 53 sec
Reputation Power: 3
CSV to Access? *Tab-delimited file*


Hola.

I have a question on Importing tab-delimited CSV to Access.

Currently I have a CSV file. Eg. *CSV1.txt*
_________________________
Field1 Field2 Field3 Field4
XX | XX | XX | XX
CC | CC | CC | CC
EE | EE | EE | EE
________________________

As you can see, the file is a tab-delimited file. So far and till now, I have only found codes that only import data that are separated by commas.

I've tried to tweak the codes but still up to no avail. I'm only able to only import 1 column from the CSV file.

Any leads to this?? Do help me muchachas en muchachos. It's reallllly important.

Reply With Quote
  #2  
Old February 13th, 2006, 03:37 AM
nofriends's Avatar
nofriends nofriends is offline
Senior Water Wizard
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Aug 2004
Location: Cape Town, RSA
Posts: 10,186 nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)  Folding Points: 107973 Folding Title: Super Ultimate Folder - Level 1Folding Points: 107973 Folding Title: Super Ultimate Folder - Level 1Folding Points: 107973 Folding Title: Super Ultimate Folder - Level 1Folding Points: 107973 Folding Title: Super Ultimate Folder - Level 1Folding Points: 107973 Folding Title: Super Ultimate Folder - Level 1Folding Points: 107973 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 2 Weeks 2 Days 7 h 36 m 24 sec
Reputation Power: 699
could you post the code you have now?

you should be able to read in the whole line and split it on vbTAB
to get the columns
__________________
Look! Its a ShemZilla



Reply With Quote
  #3  
Old February 13th, 2006, 03:45 AM
DOLL DOLL is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2006
Posts: 32 DOLL User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 50 m 53 sec
Reputation Power: 3

By all means muchacho..Hopefully you can help me solve this.
Code:
<%@ Language="VBScript" %>

<%
  'CONNECT TO THE DATABASE
  set objconn = Server.CreateObject("ADODB.Connection")
  objconn.Provider="Microsoft.Jet.OLEDB.4.0"
  objconn.Open Server.MapPath("csv.mdb")


  csv_to_read="test_csv.csv"
  set fso = createobject("scripting.filesystemobject")
  set act = fso.opentextfile(server.mappath(csv_to_read),1,Fal  se)

  dim sline
  dim sSeg
  
  Do Until act.AtEndOfStream
  
  sline=act.readline
  sSeg=split(sline,",") <-- Here. I don't know what to replace.

  dim strsql
  strsql="INSERT INTO CSV (CompanyID, CompanyName, Address, Country)"
  strsql=strsql & "VALUES('"&sSeg(0)&"', '"&sSeg(1)&"', 
  '"&sSeg(2)"', '"&sSeg(3)&"')"

  objconn.execute strsql
     
  loop
  act.close
  set act=nothing
   
  'CLOSE THE CONNECTION AND CLEAN UP
  objconn.close
  set objconn=nothing
%>

You see, I have 4 field names that I need to import but the delimitor that is used in this code is comma. And I don't know how to change it or replace it since I've tried many ways to tweak the codes. It just won't import the rest. It only imports 1 column from the CSV file.

Reply With Quote
  #4  
Old February 13th, 2006, 04:03 AM
nofriends's Avatar
nofriends nofriends is offline
Senior Water Wizard
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Aug 2004
Location: Cape Town, RSA
Posts: 10,186 nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)  Folding Points: 107973 Folding Title: Super Ultimate Folder - Level 1Folding Points: 107973 Folding Title: Super Ultimate Folder - Level 1Folding Points: 107973 Folding Title: Super Ultimate Folder - Level 1Folding Points: 107973 Folding Title: Super Ultimate Folder - Level 1Folding Points: 107973 Folding Title: Super Ultimate Folder - Level 1Folding Points: 107973 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 2 Weeks 2 Days 7 h 36 m 24 sec
Reputation Power: 699
try the following
Code:
sSeg=split(sline, vbTAB)

hope this helps

Reply With Quote
  #5  
Old February 13th, 2006, 05:08 AM
DOLL DOLL is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2006
Posts: 32 DOLL User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 50 m 53 sec
Reputation Power: 3
oohh..i never think of that..i'll try that tomorrow..i'm off! toodles!

Reply With Quote
  #6  
Old February 13th, 2006, 05:18 AM
nofriends's Avatar
nofriends nofriends is offline
Senior Water Wizard
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Aug 2004
Location: Cape Town, RSA
Posts: 10,186 nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)  Folding Points: 107973 Folding Title: Super Ultimate Folder - Level 1Folding Points: 107973 Folding Title: Super Ultimate Folder - Level 1Folding Points: 107973 Folding Title: Super Ultimate Folder - Level 1Folding Points: 107973 Folding Title: Super Ultimate Folder - Level 1Folding Points: 107973 Folding Title: Super Ultimate Folder - Level 1Folding Points: 107973 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 2 Weeks 2 Days 7 h 36 m 24 sec
Reputation Power: 699
I have tested it already and it works

let us know what happens

Reply With Quote
  #7  
Old February 13th, 2006, 07:55 PM
DOLL DOLL is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2006
Posts: 32 DOLL User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 50 m 53 sec
Reputation Power: 3

It works man! The first thing that I did the moment I reach my work place is to replace the (sLine, "") to (sLine, vbTab) and boy does it work like magic!

Gracias muchacho! Really helped me in there.

But then what happens if the CSV file have more than 20 columns of data?
==============================================
Field 1..|..Field 2..|..Field 3..|..............................|..Field 22
==============================================
QQ...... |..WW.....|....................................... .....| WW |

What would happen there? Actually how does it reads a CSV file? What if there are titles on the header of the CSV file? Eg.
Invalid Purchases 20/05/2005
... ... .. .. ... .... .... .... .... .... .... ....
... ... ...... ... . . . . .. . ..... .....

How about that?

Reply With Quote
  #8  
Old February 14th, 2006, 02:01 AM
nofriends's Avatar
nofriends nofriends is offline
Senior Water Wizard
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Aug 2004
Location: Cape Town, RSA
Posts: 10,186 nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)  Folding Points: 107973 Folding Title: Super Ultimate Folder - Level 1Folding Points: 107973 Folding Title: Super Ultimate Folder - Level 1Folding Points: 107973 Folding Title: Super Ultimate Folder - Level 1Folding Points: 107973 Folding Title: Super Ultimate Folder - Level 1Folding Points: 107973 Folding Title: Super Ultimate Folder - Level 1Folding Points: 107973 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 2 Weeks 2 Days 7 h 36 m 24 sec
Reputation Power: 699
I am glad it worked,

the file is being read line by line, so if you now that the first line
is only a heading, then you can just skip the first line of the file.

It doesn't matter how many columns the csv file have, just as long
as you now which ones you want to save into the db

Reply With Quote
  #9  
Old February 14th, 2006, 02:17 AM
DOLL DOLL is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2006
Posts: 32 DOLL User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 50 m 53 sec
Reputation Power: 3
Gracias senor....

Reply With Quote
  #10  
Old February 14th, 2006, 02:24 AM
nofriends's Avatar
nofriends nofriends is offline
Senior Water Wizard
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Aug 2004
Location: Cape Town, RSA
Posts: 10,186 nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)  Folding Points: 107973 Folding Title: Super Ultimate Folder - Level 1Folding Points: 107973 Folding Title: Super Ultimate Folder - Level 1Folding Points: 107973 Folding Title: Super Ultimate Folder - Level 1Folding Points: 107973 Folding Title: Super Ultimate Folder - Level 1Folding Points: 107973 Folding Title: Super Ultimate Folder - Level 1Folding Points: 107973 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 2 Weeks 2 Days 7 h 36 m 24 sec
Reputation Power: 699
no problemo

Reply With Quote
  #11  
Old February 14th, 2006, 07:56 PM
DOLL DOLL is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2006
Posts: 32 DOLL User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 50 m 53 sec
Reputation Power: 3

Senorr..
I have abit of a problem.

I thought all my CSV tab-delimited files are well..tab-delimited but when I check it again, it is
not separated by tab-spacing. It was actually.......just...space-delimited. Gosh.. I have searched the entire Google but there ain't seem to have an answer for these space-delimited CSV files. Is there Senorr?

Can I replace the space to a tab? If so, what are the ways to write it?

Reply With Quote
  #12  
Old February 15th, 2006, 09:35 AM
Darius Darius is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 108 Darius User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 16 m 54 sec
Reputation Power: 5
The traditional CSV is "," as a separator, in Windows "Control Pannel", "Regional Settings" and "Number" configuration of "List Separator" must be a "," not a tab.

For space the split(sline," ") or split(sline,chr(32)) could work.

Reply With Quote
  #13  
Old February 16th, 2006, 05:18 AM
DOLL DOLL is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2006
Posts: 32 DOLL User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 50 m 53 sec
Reputation Power: 3
Oh vo yer..But I've tried split(sLine," ") but it wouldn't work. There was an error:Subscript out of range : [-1] or so like that. And it was pointing towards the line >> split(sLine," ")
What could the error message means?

Reply With Quote
  #14  
Old February 16th, 2006, 09:48 AM
Darius Darius is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 108 Darius User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 16 m 54 sec
Reputation Power: 5
The only way to have such error is if sline="", but the same for any other kind of separator.

so:

if sline<>"" then Line = split(sline," ")

Reply With Quote
  #15