Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
Creating CSv file from database
Author:
Vimal Lakhera
E-mail:
Click to e-mail author
Website:
http://geocities.com/vimallakhera
Submitted:
9/24/2005
Version:
ASP.NET 1.1
Compatibility:
ASP.NET 1.0, ASP.NET 1.1
Category:
Databases
Views:
21675
Creating CSv file from database. Code is in C#.
Declarations:
'none
Code:
public void genrateCsv(string strQuery,string fileName) { SqlCommand command = new SqlCommand(strQuery,sqlConn); //open the connection command.Connection.Open(); //create the sqldataadapter that would hold the result set SqlDataAdapter sqlAdapter = new SqlDataAdapter(command); //create our datatable DataTable dataTable = new DataTable(); //fill the datatable with the values fetched from our query sqlAdapter.Fill(dataTable); //set the conttent type of the file to be downloaded HttpContext.Current.Response.ContentType = "Application/x-msexcel"; //add the response headers HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=\"" + fileName+ "\""); //add the contents of the result set to the response stream and generate our csv file HttpContext.Current.Response.Write( ToCSV(dataTable) ); //close the connection command.Connection.Close(); //end the http response HttpContext.Current.Response.End(); }
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement