SQL如何从索引中选择列而不是从csv中选择名称

时间:2016-03-16 16:34:22

标签: sql vba csv oledb adodb

Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim sql As String
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                "Data Source=" & ThisWorkbook.Path & ";" & _
                "Extended Properties='Text;HDR=No'"

sql = "SELECT Col1 FROM abc.csv"
rs.Open sql, cn, adOpenKeyset, adLockOptimistic

如果使用vba从csv文件中没有列标题行,如何按列号选择Col1?

1 个答案:

答案 0 :(得分:0)

您可能需要以不同方式处理读取,但此解决方案适合您。

Link to StackOverflow Q/A that will help you

sql = "SELECT * FROM abc.csv"
rs.Open sql, cn, adOpenKeyset, adLockOptimistic
var column1 = "";

Do While Not rsCSV.EOF
    column1 = rs.Fields(0)
    'Do something with the column1 data
    rs.MoveNext
Loop