classic asp - reading csv file having alphanumeric data

ⅰ亾dé卋堺 提交于 2019-12-07 13:51:31

问题


I'm having trouble in reading csv file that are having alphanumeric data. below is my code in classic asp:

strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
ls_map_path & ";Extended Properties=""Text;HDR=Yes;FMT=Delimited"";"


Set lo_conn = Server.CreateObject("ADODB.Connection")
lo_conn.Open strConn

Set lo_rs = Server.CreateObject("ADODB.recordset")
lo_rs.CursorLocation = adUseClient
lo_rs.open "SELECT * FROM " & as_file_name, lo_conn, adOpenStatic, adLockOptimistic, adCmdText

and below is the data:

user_id,status,last_name,first_name,middle_name 
1234,1,DeVera,athan,M. 
1234,1,De Vera,athan,M. 
ABC1,1,Santos,Shaine
abcd,1,Santos,Luis 
1234,1,De Vera,athan,M. 
1234,1,De Vera,athan,M.
ABC1,1,Santos,Shaine

When reading "user_id" column using lo_rs.fields.Item("user_id"), it perfectly retrieve the "1234" user_id value. but other data that are having alphanumeric value is returning me a null.

I don't know the reason why it is returning null. Though, if the data is all alphanumeric then it perfectly reads the user_id column. I think the only problem is, if the csv data is having a mix numeric and alphanumeric value in one column.

Does anyone know how to resolve this? or maybe I just have a missing text in the connection string.

Please advise and thank you very much for the help in advance!


回答1:


To get around the type inference you can create a SCHEMA.INI that defines the types of each column in the CSV file.

Set HDR=NO & in the directory containing the CSV (ls_map_path) create a schema.ini:

[filenamehere.csv]
Col1=user_id Text
Col2=status Long
Col3=last_name Text
Col4=middle_name Text

The type mappings used by the text provider are now based on the above schema.



来源:https://stackoverflow.com/questions/6981234/classic-asp-reading-csv-file-having-alphanumeric-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!