简体   繁体   English

如何使用c#winform将10,000行数据从存储过程移动到excel

[英]How to move 10,000 rows of data from a Stored Procedure to excel using c# winform

The situation is as follows - 情况如下 -

  • UserX wants information about PlayerY. UserX需要有关PlayerY的信息。
  • Currently I get details about PlayerY and run two sql scripts that return two data sets - each one being approximately 10,000 records. 目前我获得有关PlayerY的详细信息并运行两个返回两个数据集的sql脚本 - 每个数据集大约有10,000个记录。
  • I then manually copy and paste these sets into an Excel workbook and email this to UserX 然后,我手动将这些集复制并粘贴到Excel工作簿中,并通过电子邮件发送给UserX

Current planned approach: 目前的计划方法:

  1. I will create a simple WinForm or WPF, for UserX, that will accept input of the details of PlayerY. 我将为UserX创建一个简单的WinForm或WPF,它将接受PlayerY详细信息的输入。
  2. I will create two stored procedures that will accept input from the form. 我将创建两个将接受表单输入的存储过程。

How does the data get from the database to UserX's client? 数据如何从数据库传输到UserX的客户端?

I ask because the data sets are quite large and there may be unforeseen problems with certain approaches because of the size. 我问,因为数据集非常大,并且由于尺寸的原因,某些方法可能存在无法预料的问题。 Should the stored procs first move the data to actual server tables, then have a second step and move the data from the server tables into Excel? 如果存储过程首先将数据移动到实际的服务器表,那么还有第二步并将数据从服务器表移动到Excel中吗? Or should I just have the stored procedures return the datasets as it will be easy enough to move them direct into XL without any intermediate server tables? 或者我应该让存储过程返回数据集,因为它很容易将它们直接移动到XL而没有任何中间服务器表?

If you plan to fetch record thr' c#, 如果你打算获取记录thr'c#,

Instead of fetching 10000 or more records one at time, fetch specific no. 而不是一次获取10000条或更多条记录,而是获取特定的no。 of records eg 1000, 10 times. 记录,例如1000次,10次。 That will make process quicker & less memory load. 这将使流程更快,内存负载更少。

You don't need to create any intermediate server table to store dataset. 您无需创建任何中间服务器表来存储数据集。

Using DocumentFormat.OpenXml.Spreadsheet in c#, you can write that dataset to Xlsx format or create xml file using System.xml or use thrid party tool/create own excel xml, to create xls format. 使用c#中的DocumentFormat.OpenXml.Spreadsheet,您可以将该数据集写入Xlsx格式或使用System.xml创建xml文件或使用thrid party工具/创建自己的excel xml来创建xls格式。

I would suggest that you create .csv file from the results returned by your stored procedure at run-time using C#, a .csv file can be opened in Excel so you still have excel as the application at the end 我建议您使用C#在运行时从存储过程返回的结果创建.csv文件,可以在Excel中打开.csv文件,这样您仍然可以在应用程序结束时使用Excel作为应用程序

Also please see this link hence i did not recommend you using Automation of Office 另请参阅此链接,因此我不建议您使用Office自动化

Paragraph taken from http://support.microsoft.com/kb/257757 Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment. http://support.microsoft.com/kb/257757获取的段落 Microsoft目前不建议也不支持从任何无人参与的非交互式客户端应用程序或组件(包括ASP,ASP.NET)自动化Microsoft Office应用程序,DCOM和NT服务),因为Office在此环境中运行时可能会出现不稳定的行为和/或死锁。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在C#中使用Selenium IE驱动程序来快速发布大量文本(10,000行) - Using Selenium IE driver in C# to quickly post a large amount of text (10,000 lines) 在C#winform中从SQL存储过程返回结果和消息 - Returning results and messages from a SQL Stored procedure in a C# winform 将日期参数从C#WinForm传递到SQL存储过程 - Passing Date parameter from C# WinForm to SQL stored procedure 使用C#从存储过程中检索多行 - Retrieving multiple rows from stored procedure using c# 打印从0到10,000的素数 - Print the prime numbers from 0 to 10,000 使用带有存储过程的 C# 从 sql 数据库中检索数据 - retrieving data from sql database using C# with stored procedure 如何读取包含超过 200,000 行的大型 excel 文件并将该数据加载到 C# 中的数据表中 - How to read large excel files containing more that 200,000 rows and load that data in datatable in C# C#LINQ-SQL帮助-查询超过10,000个项目的数据库 - C# LINQ-SQL Help - Querying DB over 10,000 items 在C#中针对10,000个文件优化1000个正则表达式搜索 - Optimizing 1000 regex searches across 10,000 files in C# 如何使用C#中的存储过程在Oracle数据库中插入数据? - How to insert data in oracle database using stored procedure in c#?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM