国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

數據島出到Excel最為簡易的方法

2019-11-18 17:08:43
字體:
來源:轉載
供稿:網友

只需將ContentType 設置為 "application/vnd.ms-Excel",表示以Excel方式輸出.
代碼如下:
DataToExcel.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DataToExcel.aspx.cs" Inherits="DataToExcel" %>

<html xmlns="<head runat="server">
    <title>DataToExcel</title>
</head>
<body>
    <form id="form1" runat="server">
            <asp:GridView ID="GridView1" runat="server">
            </asp:GridView>
    </form>
</body>
</html>DataToExcel.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class DataToExcel : System.Web.UI.Page
{
   
PRotected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            this.Response.ContentType = "application/vnd.ms-excel";
            string ConnStr = "server=localhost;uid=sa;pwd=;database=northwind";
            SqlConnection Conn = new SqlConnection(ConnStr);
            Conn.Open();
            string sqlcmd = "select lastname,firstname,title, address, city from employees";
            SqlCommand cmd = new SqlCommand(sqlcmd, Conn);
            SqlDataAdapter adapter = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            adapter.Fill(ds);
            this.GridView1.DataSource = ds.Tables[0].DefaultView;
            this.GridView1.DataBind();
        }
    }
}
http://ring1981.VEVb.com/archive/2006/06/19/429919.html


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 蒙山县| 突泉县| 多伦县| 旅游| 苍南县| 桑植县| 精河县| 大兴区| 红河县| 宜都市| 闸北区| 镇原县| 安福县| 凤庆县| 手游| 舒兰市| 鄂州市| 崇左市| 宁明县| 政和县| 辉县市| 大邑县| 临颍县| 金秀| 贵南县| 太仆寺旗| 凤山市| 丘北县| 佛学| 左权县| 华亭县| 韶关市| 英吉沙县| 措美县| 丹寨县| 利辛县| 西丰县| 彰化县| 东莞市| 射阳县| 盘山县|