Rearrange columns in a recordset before writing to excel RRS feed

  • Question

  • Hi,

    I am fetching data from databse in ADODB._Recordset and I am writing it to excel using CopyFromRecordset method. Before writing to excel, I want to rearrange the column order in recordset. Is there anyway to do this.



    • Moved by Cindy Meister MVP Wednesday, June 29, 2011 8:45 AM Data manipulation-related (From:Visual Studio Tools for Office)
    Wednesday, June 29, 2011 5:35 AM


  • Hello,

    Thank you for posting.

    From your description, you can directly get data from database. Based on my description, you may create a custom table column for your sql query statement in your project. I think this is a good way for your to create a flexible application to dynamically get data. Plus, you can consider changing the column order when you inserted data into Excel. My option is you can do something during data read/write. But this isn't very good choice.

    In addition, you can import the data into memory (DataTable or others) and then you can create your custom table and export it to Excel. But I think this is also a later and not a good way. As I were you, I consider operating this at sql server level.

    Hope this helps. If I misunderstood, please feel free to let me know.

    Best Regards,

    Larcolais Gong[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, July 1, 2011 7:44 AM