ASP.NET简单快速生成静态页面html
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);
}
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);
}
- 上一篇:C#、ASP.NET程序员面试基础问题和答案
- 下一篇:一些很酷的.Net技巧
精彩图集
精彩文章