将数据从sql 2005导出到excel 2007 [英] export data from sql 2005 to excel 2007

查看:127
本文介绍了将数据从sql 2005导出到excel 2007的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI

   如何使用c#将数据从sql server 2005导出到excel 2008,然后一旦下载包含数据,将从数据库中删除数据.....

   how to export data from sql server 2005 to excel 2008 using c# and then once download contain data will be remove from database.....

推荐答案

如果您有一个真实" SQL Server 2005(非Express版),那么我建议从SQL Server而不是C#进行此操作.只需打开SQL Server Management Studio,然后从服务器资源管理器中选择导出数据"选项.这将打开 一个向导,您可以在其中选择数据源(您的数据库和表)和目的地(您的Excel电子表格).该向导将生成一个SSIS包,您可以立即运行该SSIS包,也可以将其保存以在需要时运行.包可以是 如果需要,可以从Business Intelligence Development Studio中进行编辑以添加一个任务,该任务可以在导出后删除行.如果需要从C#程序中运行程序包,则可以通过以下两种方法来完成:可以使用Process.Start运行dtexec.exe. 并通过包作为参数,也可以将软件包安装到SQL代理的工作,然后从C#使用SqlCommad发送SQL语句将启动该作业;这只需要三行代码.

If you have a "real" SQL Server 2005 (not the Express edition), then I would suggest doing this from the SQL Server side instead of C#. Just open SQL Server Management studio and from the server explorer select the option to "export data". This will open a Wizard where you can select the data source (your database and table) and the destination (your Excel Spreadsheet). The Wizard will generate a SSIS package that you can run immediately or you can save for running whenever it is needed. The package can be edited from Business intelligence Development Studio to add a Task that deletes the rows after exporting, if you so desire. If you need to run the package from within a C# program, it can be done in a couple of ways: You can use Process.Start to run dtexec.exe and pass the package as an argument, or you can install the package into a Job of the SQL Agent and then from C# use a SqlCommad to send a SQL Statement that launches the Job; this only takes three lines of code.


这篇关于将数据从sql 2005导出到excel 2007的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆