Click here to Skip to main content
12,358,242 members (70,103 online)
Rate this:
 
Please Sign up or sign in to vote.
The database named db have three tables called A,B,C,How to acheive this effect:in a dropdownlist user select one table(A,B,C from DB) and click a button ,than export the table which format is excel?(no showing the table in the web page,just select the table,click the button and that export the table)

I can operate it manually by set the excel's datasource,but I don't know how to acheive it by coding?
Posted 7-Jul-12 19:27pm
Edited 7-Jul-12 19:36pm
v2
Comments
DaveAuld 8-Jul-12 1:31am
   
You do not tell us where you are selecting the table names from, is it a web app, from within excel userforms, or some other input medium. Please edit your question with more info, and set the tags as well. Also sort the subject to a meaningful one and not just a repeat of the question, e.g. Select and export SQL table to Excel file from Web page.
PEIYANGXINQU 8-Jul-12 1:37am
   
OK,I have edited again,Thank you!
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

hi,
take a look at this post:
Export Data to Excel, Word, PDF without Automation from DataBase[^]

Hope it will help,
Cheers
  Permalink  
Comments
PEIYANGXINQU 8-Jul-12 3:20am
   
Thank you,I find a bug in the software,when export time ,it seems wrong
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Hi,

Check following link :
Exporting Data to Excel[^]
hope it will help youSmile | :)
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

SqlDataAdapter da = new SqlDataAdapter("select * from Sample", con); // SqlDataAdapter da = new SqlDataAdapter( "select * from"+"'Dropdownlist1.selecteditem.text'"+"" ", con);
    DataSet ds = new DataSet();
    da.Fill(ds);
 
    System.IO.StringWriter stringWrite = new System.IO.StringWriter();
 
   System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
 

   dgrid.DataSource = ds;
 

   htmlWrite.WriteLine("hello");
 
   dgrid.DataBind();//Data Grid Bind

   dgrid.RenderControl(htmlWrite);
 
   Response.Clear();
    string str="Student";
    Response.AddHeader("content-disposition", "attachment;filename='"+str+"'"+".xls");
 
    Response.Charset = "";
 
   Response.Cache.SetCacheability(HttpCacheability.NoCache);
 
   Response.ContentType = "application/vnd.xls";
 
   Response.Write(stringWrite.ToString());
   Response.End();
Hope it will helpful for you
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160621.1 | Last Updated 9 Jul 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100