-
Aug 6th, 2009, 10:52 AM
#1
Thread Starter
New Member
Using recordset to read a csv file- Problem with values
Hello!
Im opening a csv file using adodb.
No problems opening, but when i try to retrieve a value from a column that has 10 or more characters, it just dont return.
But it only happens with numbers. Imagine i have a column with value 1234567890
objRecordset.Fields.Item(0).Value returns null
but if its 123456789, it returns the number.
Same happens with plain text. Allways return the all text.
How can i set to return more than 9 characters?
Thanks in advance
-
Aug 6th, 2009, 11:22 AM
#2
Re: Using recordset to read a csv file- Problem with values
You may want to show us your connection string. Sounds like that field is being interpreted as Long vs string. What does objRecordset.Fields(0).Type return?
-
Aug 6th, 2009, 11:34 AM
#3
Thread Starter
New Member
Re: Using recordset to read a csv file- Problem with values
Set m_objCollection = New Collection
Set m_objConnection = New ADODB.Connection
Set m_objRecordset = New ADODB.Recordset
m_objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & App.Path & ";" & _
"Extended Properties=""text;HDR=YES;FMT=Delimited"""
m_objRecordset.Open "SELECT * FROM " & strFicheiro, m_objConnection, adOpenStatic, adLockOptimistic, adCmdText
and the type is 3, where the text column is 202
-
Aug 6th, 2009, 11:43 AM
#4
Re: Using recordset to read a csv file- Problem with values
type 3 = adInteger, type 202 = adVarWChar
Is this a csv you create? If so, when you write the csv values, surround them with "" characters, i.e., Chr$(34). That should force the interpretation to string vs numeric, assuming string is the intent.
-
Aug 6th, 2009, 11:48 AM
#5
Thread Starter
New Member
Re: Using recordset to read a csv file- Problem with values
this csv comes from excel.
how can i change that? this "little" problem is ruinning my app :S
-
Aug 6th, 2009, 11:50 AM
#6
Re: Using recordset to read a csv file- Problem with values
You may want to consider creating/using a Schema.INI file, discussed here on MSDN. You can also search this forum for Schema.ini
Of course you always have the option of manually reading/processing the file without the use of ADO.
-
Aug 6th, 2009, 12:08 PM
#7
Thread Starter
New Member
Re: Using recordset to read a csv file- Problem with values
im already using a schma.ini file because our csv are delimited by ( and not (,)
[Conv.csv]
Format=Delimited(
but, how can i use the schema.ini file to change the data type?
-
Aug 6th, 2009, 12:35 PM
#8
Re: Using recordset to read a csv file- Problem with values
Originally Posted by MSDN
Col1=LastName Text
Col2=FirstName Text
Col3=MiddleInitial Text
Notice that you need to indicate the type of data contained in the field. In this case, all three fields contain text (string) data. Other data types you can specify in a Schema.ini file include:
* Short
* Long
* Currency
* Single
* Double
* DateTime
* Memo
Suggest taking 5 minutes and reading the entire page in the link I provided, then trying it, to see it your issue is resolved.
-
Aug 6th, 2009, 12:41 PM
#9
Thread Starter
New Member
Re: Using recordset to read a csv file- Problem with values
Thank you m8.
Got it resolved
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
|