开发者

classic asp - reading csv file having alphanumeric data

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 anyo开发者_JAVA百科ne 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!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜