简体   繁体   中英

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.
  • Currently I get details about PlayerY and run two sql scripts that return two data sets - each one being approximately 10,000 records.
  • I then manually copy and paste these sets into an Excel workbook and email this to UserX

Current planned approach:

  1. I will create a simple WinForm or WPF, for UserX, that will accept input of the details of 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?

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? 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?

If you plan to fetch record thr' c#,

Instead of fetching 10000 or more records one at time, fetch specific no. of records eg 1000, 10 times. 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.

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

Also please see this link hence i did not recommend you using Automation of 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM