Re: Error using ado to read cvs file



Light schrieb:
Hi All,

I am using the following code to read csv file, but I am getting error if the data in the following column is having the different format.

For example, I have two rows:

1234, 1234
abcd, 1234

Instead of getting abcd, I will get a null string. If the column in the second row is also a number likes 56789, it will be fine. The same error goes for the second column if the data format changed.

So is my set up correct?
------------------------------------------------
Set Conn = Server.CreateObject("ADODB.Connection")
strConn = "Driver={Microsoft Text Driver (*.txt;*.csv)};" & _
"DefaultDir=" & path
'Opens the connection to the data store
Conn.Open strConn

' csv file
strCmd = "SELECT * from [" & filename & "]"

Set RS = Server.CreateObject("ADODB.Recordset")
'Opens the recordset
RS.Open strCmd, Conn,adOpenStatic,adLockReadOnly

oRs.Fields(0).Value = "" if data format changed from the previous row.
--------------------------------------------------

TIA

P.S. If I am in the wrong NG, please point me to the correct one.

The text driver guesses at the format of a .csv file, if he/she/it
doesn't find a schema.ini file containing the specification/definition
in the same directory. So create such a file - c.f.

http://support.microsoft.com/?scid=kb%3Ben-us%3B187670&x=18&y=14

and give CHAR as data type for your columns.
.



Relevant Pages

  • Error using ado to read cvs file
    ... I am using the following code to read csv file, but I am getting error if the data in the following column is having the different format. ... Instead of getting abcd, I will get a null string. ... If the column in the second row is also a number likes 56789, ... 'Opens the connection to the data store ...
    (microsoft.public.data.ado)
  • Re: CSV Downloads
    ... Open/Save As prompt when you click your bank statement (.CSV file). ... > am presented with a file download box. ... On the XP machine I select CSV and Excel is opened ... >> opens in IE, just do File/Save As and save it as .xls or whatever. ...
    (microsoft.public.windowsxp.help_and_support)
  • CSV and XLS (was Re: How to make IE accept it is NOT the default browser?)
    ... that is a .csv file that is linked to for download. ... >Note that .CSV also opens with Excel. ... successfully using IE6. ...
    (microsoft.public.windows.inetexplorer.ie6.browser)
  • Re: CSV File Problem
    ... You'll see a text to columns wizard and you can specify that your fields be ... BUT, if I double click on the csv file so it opens in Excel, then it looks ... Microsoft MVP - Excel ...
    (microsoft.public.excel)
  • Re: Cant stop Excel re-calculating on opening - hmmm...
    ... then I do this code just to open a file - it's a CSV file which opens ... Excel calculates the WHOLE CALCULATIONS spreadsheet when I ... open the CSV file, ...
    (microsoft.public.excel.programming)