Can export more than on table in a dataset to Excel

G

Guest

I used the code below to export a table in a dataset to Excel.
It can export only on table at a time.
Can export more than on table in a dataset to Excel


public static void Convert(System.Data.DataSet ds, int TableIndex,
System.Web.HttpResponse response)
{
if (TableIndex > ds.Tables.Count - 1)
{
Convert(ds, response, ds.Tables[0].TableName);
}
response.Clear();
response.Charset = "";
response.ContentType = "application/vnd.ms-excel";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new
System.Web.UI.HtmlTextWriter(stringWrite);
System.Web.UI.WebControls.DataGrid dg = new
System.Web.UI.WebControls.DataGrid();
dg.DataSource = ds.Tables[TableIndex];
dg.DataBind();
dg.RenderControl(htmlWrite);
response.Write(stringWrite.ToString());
response.End();
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top