如何将数据从SQL Server(使用查询)导出到Excel文件

问题描述:

我是VB.net编程的新手,并开始使用Visual Studio Community 2015.

I am new to programming on VB.net and start using Visual Studio Community 2015.

我需要做的是单击按钮(我有一个表单),然后在SQL中进行选择(我写了查询),然后将其粘贴到Excel电子表格中.我已经在网上搜索了一些示例,发现了以下内容,但对我来说却无法正常工作,错误发生在:  Microsoft.Office.Interop.Excel.Worksheet/Application

What I need to do is on single button click (I have a form) make a selection in SQL (I have written query) to be pasted on Excel spreadsheet. I have searched for examples on web, found the below, but it does not properly work for me, eror occurs on: Microsoft.Office.Interop.Excel.Worksheet/Application

我已将Microsoft Excel 16.0对象库添加到我的项目中

发生什么错误,并在哪一行代码上发生?
What is the error and on which line of code does it occur?