SqlConnection con = new SqlConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["carConnectionString"].ToString());
{
string cmd1 = "select * from trytable";
SqlDataAdapter da = new SqlDataAdapter(cmd1, con);
DataSet ds = new DataSet();//创建数据集
da.Fill(ds);//填充数据集
DataTable dt = ds.Tables[0];
GridView gvOrders = new GridView();
Response.Clear();
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "GB2312";
Response.AppendHeader("Content-Disposition", "attachment;filename=PhenixUpdateDataLog.xls");
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312"); //设置输出流为简体中文
this.EnableViewState = false;
Response.Write("<meta http-equiv=Content-Type content=\"text/html; charset=GB2312\">");
System.IO.StringWriter sw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(sw);
gvOrders.AllowPaging = false;
gvOrders.AllowSorting = false;
gvOrders.DataSource = dt;
gvOrders.DataBind();
gvOrders.RenderControl(hw);
Response.Write(sw.ToString());
Response.End();
}