查询CSV文件,带有句点的表名

时间:2017-06-13 06:10:56

标签: sql vba csv qtp hp-uft

我创建了一个查询CSV文件的功能。一切正常......但是,当标题包含句点时,它会生成错误。 (这是在UFT / QTP中)。

'Create ADODB connection object
Set objConnection = CreateObject("ADODB.Connection")


'Create Recordsetobject
Set objRecordSet = CreateObject("ADODB.Recordset")

objConnection.Provider  = "Microsoft.Jet.OLEDB.4.0"
objConnection.ConnectionString = "Data Source=" & strCSVpath & ";" & "Extended Properties=""text;HDR=Yes;FMT=Delimited"""
objConnection.Open

'Execute the query
objRecordSet.open sqlQuery, objConnection 

value = objRecordSet.fields.item(0)                 

objRecordSet.Close
objConnection.Close
Set objConnection = Nothing
Set objRecordSet = Nothing

CSV包含以下内容:

head1;head2;hea.d3;
val1;val2;val3;

读取标题3(hea.d3)会出错。 试过:

"Select hea.d3  from [test.csv] "
"Select [hea.d3]  from [test.csv] "
"Select (hea.d3)  from [test.csv] "

非作品......任何人都可以给我建议吗?

干杯, GIEL

1 个答案:

答案 0 :(得分:0)

解决方案:

select [hea#d3] from [test.csv] 

感谢。