请问一个dataset中的数据导出成excel的有关问题

请教一个dataset中的数据导出成excel的问题。
.net的只是有限,需要将dataset中的数据导出成一个excel文件,网上搜了一段别人的代码,试了下总是报错,还请各位高手指点。谢谢!
报错信息:
ID 为“”的 DataGrid 未能从选定数据源自动生成任何列。 
说明: 执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 

异常详细信息: System.Web.HttpException: ID 为“”的 DataGrid 未能从选定数据源自动生成任何列。


代码如下:
.aspx.cs文件:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.IO;

public partial class excel2 : System.Web.UI.Page
{
    DBClass db = new DBClass();
    DataTable mytb = new DataTable();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            GridViewBind();
        }
    }

    public void GridViewBind()
    {
        DataSet ds = db.GetDataSet("select top 10 rybm,ryname from hmc", "test");
        if (ds.Tables["test"].Rows.Count > 0)
        {
            this.GridView1.DataSource = ds;
            this.GridView1.DataBind();
            mytb = ds.Tables["test"];
        }
    }

    /// <summary> 
    /// 把DataTable内容导出excel并返回客户端 
    /// </summary> 
    /// <param name="dgData">待导出的DataTable</param> 
    /// 创 建 人:陈文凯 
    /// 创建日期:2005年10月08日 
    /// 修 改 人: ranbolwb  修改导出中文乱码的问题
    /// 修改日期: 2012-05-29
    public static void DataTable2Excel(System.Data.DataTable dtData)
    {
        System.Web.UI.WebControls.DataGrid dgExport = null;
        // 当前对话 
        System.Web.HttpContext curContext = System.Web.HttpContext.Current;
        // IO用于导出并返回excel文件 
        System.IO.StringWriter strWriter = null;
        System.Web.UI.HtmlTextWriter htmlWriter = null;

        if (dtData != null)
        {
            // 设置编码和附件格式 
            curContext.Response.ContentType = "application/vnd.ms-excel";
            curContext.Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
            curContext.Response.Charset = "gb2312";

            // 导出excel文件 
            strWriter = new System.IO.StringWriter();
            htmlWriter = new System.Web.UI.HtmlTextWriter(strWriter);

            // 为了解决dgData中可能进行了分页的情况,需要重新定义一个无分页的DataGrid 
            dgExport = new System.Web.UI.WebControls.DataGrid();
            dgExport.DataSource = dtData.DefaultView;
            dgExport.AllowPaging = false;
            dgExport.DataBind();

            // 返回客户端 
            dgExport.RenderControl(htmlWriter);
            curContext.Response.Clear();
            curContext.Response.Write("<meta http-equiv=\"content-type\" content=\"application/ms-excel; charset=gb2312\"/>" + strWriter.ToString());
            curContext.Response.End();
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        DataTable2Excel(mytb);
    }
}

.aspx文件:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="excel2.aspx.cs" Inherits="excel2" EnableEventValidation = "false"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
<div>
    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
    </div>
<div>
    <asp:GridView ID="GridView1" runat="server">
    </asp:GridView>
    <br />
    </div>
    </form>
</body>
</html>



*****************

------解决思路----------------------
OLEDB方式http://blog.****.net/yangmingxing980/article/details/39048795

NPOI方式http://blog.****.net/yangmingxing980/article/details/40428915