ADODB recordset column headers

人盡茶涼 提交于 2019-12-24 08:18:35

问题


I'm copying ADODB.Recordset data to excel file, but it copies the recordset data to excel without column headers.I'm using MS Access 2013, CompyFromRecordset command.

my question is, is there any way to copy the data headers of RecordSet?

For i = 0 To iFieldCount - 1
    objSheet.Range("A" & i + 1).CopyFromRecordset rst
    objBook.Save
Next i

回答1:


A "header" is not a record and the CopyFromRecordset command does not include the headers.

You must put the header in your sheet yourself by iterating over the fieldnames of the returned recordset, something like:

For i = 1 To iFieldCount
    objSheet.Range("A" & i) = rst.Field(i).Name
Next i

(Note: I didn't test the code; there may be some errors.)



来源:https://stackoverflow.com/questions/36568793/adodb-recordset-column-headers

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