Pushing query result in an excel or csv file. 
June 22nd, 2009, 03:27 PM
| | Member | | Join Date: Jun 2009 Location: Bangalore
Posts: 41
| | |
Hi Guys,
Is it possible to have query result in a excel or csv file instead of having it in a datareader or dataset. please let me konw one or the other way to do it.
Thanks,
Manik
| 
June 24th, 2009, 12:13 PM
| | Expert | | Join Date: Jan 2008 Location: York
Posts: 178
| | | re: Pushing query result in an excel or csv file.
Well if it's in some sort of a dataset, I'm assuming you can itterate over rows and columns?
If so you could just built a little CSVWriter of your own?
| 
June 24th, 2009, 03:32 PM
| | Administrator | | Join Date: Sep 2006
Posts: 12,084
| | | re: Pushing query result in an excel or csv file.
Also your database probably already supports a command that exports data as csv.
| 
June 24th, 2009, 04:24 PM
|  | Forum Leader | | Join Date: Apr 2008 Location: San Antonio, TX (USA)
Posts: 2,569
| | | re: Pushing query result in an excel or csv file.
There is no framework element that will automatically dump your query into a CSV from code. But as Ian suggested, just iterate through your results and make your own.
| 
June 25th, 2009, 07:23 AM
| | Administrator | | Join Date: Sep 2006
Posts: 12,084
| | | re: Pushing query result in an excel or csv file. Quote:
Originally Posted by insertAlias There is no framework element that will automatically dump your query into a CSV from code. But as Ian suggested, just iterate through your results and make your own. | But using the built in database commands would be much faster as the commands are already well optimized for that and there will be no need to write any code. Generally it is better to do with code only what the database cannot do.
| 
June 25th, 2009, 02:20 PM
|  | Forum Leader | | Join Date: Apr 2008 Location: San Antonio, TX (USA)
Posts: 2,569
| | | re: Pushing query result in an excel or csv file.
Right, I was assuming that he had some need to do it programatically, possibly part of a larger process. If not, your way is definitely best.
| 
July 1st, 2009, 12:25 PM
| | Member | | Join Date: Jun 2009 Location: Bangalore
Posts: 41
| | | re: Pushing query result in an excel or csv file.
It was very easy, sharing it for others. You can put your datagrid in the excel file with the same grid feel. - myDataGrid.DataSource = ds;
-
myDataGrid.DataBind();
-
dbConn_data.Close();
-
myDataGrid.Visible=true;
-
//Adding Grid data in Excel sheet -start
-
Response.Clear();
-
Response.AddHeader("content-disposition", "inline;filename=SurveyReport.xls");
-
Response.Charset = "";
-
Response.Cache.SetCacheability(HttpCacheability.NoCache);
-
Response.ContentType = "application/vnd.xls";
-
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
-
myDataGrid.RenderControl(htmlWrite);
-
Response.Write(stringWrite.ToString());
-
Response.End();
|  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 225,652 network members.
|