传统的ASP - 读出具有字母数字数据csv文件 [英] classic asp - reading csv file having alphanumeric data

查看:124
本文介绍了传统的ASP - 读出具有字母数字数据csv文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有在读那些有字母数字数据csv文件的麻烦。下面是在传统的ASP我的code:

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

和下面的数据:

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

在使用 lo_rs.fields.Item(user_ID的),它完美找回1234user_ID的价值读书USER_ID一栏。但遇到字母数字值等数据返回我空。

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.

我不知道为什么它返回空的原因。不过,如果数据是所有字母数字那么完美读取user_id列。我认为唯一的问题是,如果CSV数据中有一列混合数字和字母数字值。

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!

推荐答案

要避开类型推断你可以创建一个的 SCHEMA.INI 定义类型的CSV文件中的每一列。

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

设置 HDR = NO &安培;在包含CSV目录( ls_map_path )创建Schema.ini:

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.

这篇关于传统的ASP - 读出具有字母数字数据csv文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆