龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > asp.net编程 >

ASP.NET简单快速生成静态页面html

时间:2009-12-21 11:47来源:未知 作者:admin 点击:
分享到:
string connstr = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=" + Server.MapPath("App_Data/webdb.mdb"); //数据库路径 OleDbConnection conn=new OleDbConnection(connstr); OleDbDataReader dr = null; OleDbCommand cm = null; try{ conn.Open(
        string connstr = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=" + Server.MapPath("App_Data/webdb.mdb"); //数据库路径
        OleDbConnection conn=new OleDbConnection(connstr);
        OleDbDataReader dr = null;
        OleDbCommand cm = null;
        try{
            conn.Open();
            string strsql = "select * from [web]";  //表
            cm = new OleDbCommand(strsql,conn);
            dr = cm.ExecuteReader();
            if (dr.Read())
            {
                string html = dr["txt"].ToString();
                StreamWriter sw = null;
                Encoding code = Encoding.GetEncoding("gb2312");  //指定编码
                sw = new StreamWriter(Server.MapPath("index.htm"), false, code);  //生成指定文件名
                sw.Write(html);
                sw.Flush();
                response.write("生成index.htm成功");
                sw.Close();
                sw.Dispose();
                cm.Dispose();
                dr.Dispose();
                conn.Close();
            }
        }
        catch(Exception sql){
            response.write("ERR"+sql.Message);
        }
精彩图集

赞助商链接