Your technology certification is waiting. Enroll in Cloud Class ®
Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.
One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.
dt = datatable.GetAllData();//your datatable
string attachment = "attachment; filename=excelfile.xls";
Response.ContentType = "application/vnd.ms-excel";
string tab = "";
foreach (DataColumn dc in dt.Columns)
Response.Write(tab + dc.ColumnName);
tab = "\t";
foreach (DataRow dr in dt.Rows)
tab = "";
for (i = 0; i < dt.Columns.Count; i++)
Response.Write(tab + dr[i].ToString());
tab = "\t";
Open in new window
using (SqlCommand cmd = new SqlCommand(query))
using (SqlDataAdapter dataadapter = new SqlDataAdapter())
cmd.Connection = con;
dataadapter.SelectCommand = cmd;
using (DataSet ds = new DataSet())
ds.Tables.TableName = "A";
ds.Tables.TableName = "B";
ds.Tables.TableName = "C"; -- example
using (XLWorkbook wb = new XLWorkbook())
foreach (DataTable dt in ds.Tables)
Response.Buffer = true;
Response.Charset = "";
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
using (MemoryStream PawanMemoryStream = new MemoryStream())
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
Please enter a first name
Please enter a last name
Must be at least 4 characters long.
Join and Comment
From novice to tech pro — start learning today.
Premium members can enroll in this course at no extra cost.