Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

VB6: import CSV using ADO, Regional settings problem?

 
   Database Help (Home) -> Visual Basic RSS
Next:  properties & view code  
Author Message
Zeppo

External


Since: Sep 30, 2003
Posts: 1



(Msg. 1) Posted: Sun Jun 06, 2004 6:43 pm
Post subject: VB6: import CSV using ADO, Regional settings problem?
Archived from groups: comp>lang>basic>visual>database (more info?)

Hi,

I Have some difficulties importing a comma-separated text-file using
the code below.
It doensn't work when the separator used is the comma (",").
It seems to be a conflict because the comma is also used as decimal
sign (W2k, Dutch)

When i try to import test1.csv (see below code) using this function i
get this error message:
"Item cannot be found in the collection corresponding to the requested
name or ordinal."

When i import test2.csv, using ";" as separator, everything works
fine.

I'm sure the code is OK , got it from MSDN, and ExpertsExchange.

Anyone can tell me how to handle a separator that is also being used
as decimal sign?

Thanks a million!

Jan


Public Function ReadMPBNLCsv(strFile As String)
Dim strConnect As String
Dim strDir As String
Dim strTest As String
Dim adoText As ADODB.Connection
Dim adoAccess As ADODB.Connection
Dim rcdText As ADODB.Recordset
Dim SQLtxt As String

Set adoText = New ADODB.Connection
Set adoAccess = New ADODB.Connection
Set rcdText = New ADODB.Recordset

strDir = DirectoryFromFile(strFile)

'Set up the connection for the text file.
strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source="
& strDir & ";" & "Extended
Properties=""text;HDR=YES;FMT=CSVDelimited"""

adoText.Open strConnect

'Set up the connection for the Access DB.
strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data " & "Source="
& AppPath() & "mpbm.mdb" & ";Persist Security Info=False"
adoAccess.Open strConnect

'Open text to a recordset.
rcdText.Open "SELECT * FROM mpbnl.csv", adoText, adOpenStatic,
adLockReadOnly, adCmdText

While Not rcdText.EOF
strTest = "INSERT INTO [test] ([a], [b], [c], [d]) VALUES " &
"('" & rcdText![a] & "', " & "'" & rcdText![b] & "', " & "'" &
rcdText![c] & "', " & "'" & rcdText![d] & "');"
txtImportLog.Text = strTest
MsgBox "OK"
rcdText.MoveNext
Wend

rcdText.Close
adoText.Close
adoAccess.Close
Set rcdText = Nothing
Set adoText = Nothing
Set adoAccess = Nothing

End Function


Test1.csv:
---------------------------
"a","b","c","d"
"1","2","3","4"
"5","6","7","8"
"9","10","11","12"

Test2.csv:
---------------------------
"a";"b";"c";"d"
"1";"2";"3";"4"
"5";"6";"7";"8"
"9";"10";"11";"12"

 >> Stay informed about: VB6: import CSV using ADO, Regional settings problem? 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
DMO - detachDB problem - I have the following code: Set oServer = New SQLDMO.SQLServer oServer.Connect (Servername), ServerID, ServerPwd Set oDatabase = oServer("Master") Call oServer.DetachDB(DBName, True) oServer.Close however, I continue getting the following err...

connected to mySQL using RDO,having a problem, - I have a problem,I have connected to mySql successfully. My problem is for example, when you log in it runs through this code fine and I get the correct results but....then when i log off and i log back in i get an error saying "Object invalid or no...

Access 2002 Automation problem with OpenReport - My VB 6 application needs to print a report in an Access 2002 database. This was working fine when I used Access 97 but now the application quits without any errors on the DoCmd.OpenReport line. I have my VB application references set to access 10.0. ....

sql query returns in wrong format - Hi, Hope someone can help me with this. I have MS SQL 2000 database where i have Table "PriceList" and there a column "Pricemk" wich is data type "money". All data in this column is in form "10001,35". So why when...

arrays - is there a way to concatenate the contents of an array (looping through the array) and storing each item in a comma delimited string? Thanks!
   Database Help (Home) -> Visual Basic All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]