protected void Button1_Click(object sender, EventArgs e)
{
OleDbConnection conn = new OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=|datadirectory|***.mdb;");
conn.Open();
string sql = "select count(*) from m";
OleDbCommand cmd = new OleDbCommand(sql, conn);
int rc = (int)cmd.ExecuteScalar();
try
{
sql = @"select top 65534 * into [Excel 8.0;database=" + Server.MapPath(".") + @"\**.xls].[Sheet1] from m";
cmd = new System.Data.OleDb.OleDbCommand(sql, conn);
cmd.ExecuteNonQuery();
conn.Close();
conn.Dispose();
conn = null;
Response.Write("文件已经生成,请下载!");
}
catch (Exception ex)
{
Response.Write(ex.Message.ToString());
}
}
原文地址:https://www.cnblogs.com/houweidong/p/12263218.html