国产探花免费观看_亚洲丰满少妇自慰呻吟_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


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 临武县| 西宁市| 兴安盟| 屏东市| 余江县| 柳州市| 洛隆县| 罗甸县| 霍邱县| 二手房| 仁怀市| 隆德县| 瑞安市| 绍兴县| 寿宁县| 茌平县| 文山县| 宾阳县| 新余市| 库尔勒市| 丹东市| 土默特右旗| 射洪县| 闽侯县| 宣武区| 嘉定区| 龙门县| 杭州市| 芜湖市| 新化县| 惠州市| 济源市| 泸州市| 高碑店市| 绍兴市| 乌鲁木齐市| 府谷县| 大冶市| 炎陵县| 星座| 灌南县|