Soldato
- Joined
- 25 Mar 2004
- Posts
- 16,007
- Location
- Fareham
Trying to export data from one of my ASP.NET C# pages to CSV, seems there is a lot of info out there about this but nothing I can make any sense of!
TLDR:
How can I call my Stored Procedure query and return the results into a .CSV file which the end user can either download or save? this is from my ASP.NET C# page
More Info:
Here's how the page currently works:
Phew! with that out of the way, everything is working great so far. My Stored Procedures work just fine and all the data is returned as expected.
So the next thing I want to do is let people download all the records returned by the query to CSV file. You know like when you visit a website and click a download to CSV button, and it gives you the CSV file and says to open or save?
I want to put the code to do this into my code behind page inside of a button_click event.
I thought this would be simple, but it doesn't seem to be.
I am coding this site in Visual Studio 2010 and I have only been using VS for a week or two so getting to grips with it, in general I would say I am a novice with this as i'm still trying to figure things out.
I don't necessarily want to return the results from the gridview becuase as stated the gridview only has the displayed records anyway.
There must be some way to call my TableAdapter query and hold the results in some kind of temp object, then transfer them to .CSV?
TLDR:
How can I call my Stored Procedure query and return the results into a .CSV file which the end user can either download or save? this is from my ASP.NET C# page

More Info:
Here's how the page currently works:
- I have a DataSet .XSD file which contains my TableAdapter.
- My TableAdapter contains my Stored Procedures from SQL 2008.
- My .ASPX page contains an ObjectDataSource which links to the Stored Procedure in my TableAdapter
- My .ASPX page also has a GridView which gets it's data from the ObjectDataSource.
- The GridView uses custom paging to ensure that it only retrieves the records that are displayed for performance reasons. so if there are 1000 records in total, and 100 per page, with 10 pages, the Stored Procedure returns only 100 records and then each time another page is selected those records are returned etc.
Phew! with that out of the way, everything is working great so far. My Stored Procedures work just fine and all the data is returned as expected.
So the next thing I want to do is let people download all the records returned by the query to CSV file. You know like when you visit a website and click a download to CSV button, and it gives you the CSV file and says to open or save?
I want to put the code to do this into my code behind page inside of a button_click event.
I thought this would be simple, but it doesn't seem to be.
I am coding this site in Visual Studio 2010 and I have only been using VS for a week or two so getting to grips with it, in general I would say I am a novice with this as i'm still trying to figure things out.
I don't necessarily want to return the results from the gridview becuase as stated the gridview only has the displayed records anyway.
There must be some way to call my TableAdapter query and hold the results in some kind of temp object, then transfer them to .CSV?