请教高手。如何把数据库里的4000条记录的文章内容批量生成静态页html?用循环么? 用哪个循环?for each next ? 谁能发一个完整的代码?谢谢备注:我考虑用一个模板页temp.html(替换方法),从data数据库读取记录,生成4000个以时间顺序为文件名的页面(2007070412319.html)。生成方法我会的,就是不知道如何循环生成一个个页面。生成的页面:包含标题、内容、日期,就是像新闻网站一样的静态页。请提示!!

解决方案 »

  1.   

    答案已经出来了。昨夜调试到1点睡的,喝了点咖啡,失眠了,3点才睡着。5点有人敲门,告诉我做饭的家什被盗啦,一个又脏又旧的破煤气罐被拎走了。我晕,什么事啊!!!害的的出去吃饭。北京小偷够疯狂,3天内一个院偷走2个煤气罐,一辆自行车,还有几家的空调主机,,都穷疯了,惊动了110。哎,不说了,我把代码贴出来,供大家以后参考吧。Do While dr.Read()
                Dim title = dr.Item("title")
                Dim clsss = dr.Item("class")
                Dim t = dr.Item("t")
                Dim laiyuan = dr.Item("laiyuan")
                Dim content = dr.Item("content")
                Dim smallclass = dr.Item("smallclass")
                Dim file_name = dr.Item("file_name")
                '下面首先读取模板文件,将其中的全部代码保存到一个字符串中
                Dim strTemplate As String
                Dim sr As New IO.StreamReader(Server.MapPath("template.htm"), Encoding.GetEncoding("gb2312"))
                strTemplate = sr.ReadToEnd()
                sr.Close()
                '下面利用客户输入的内容替换模板中的相应字符串
                strTemplate = strTemplate.Replace("$title$", title)
                strTemplate = strTemplate.Replace("$class$", clsss)
                strTemplate = strTemplate.Replace("$t$", t)
                strTemplate = strTemplate.Replace("$laiyuan$", laiyuan)
                strTemplate = strTemplate.Replace("$content$", content)
                strTemplate = strTemplate.Replace("$smallclass$", smallclass)
                strTemplate = strTemplate.Replace("$file_name$", file_name)
                '下面建立一个StreamWriter对象,生成HTML文件
                Dim sw As New IO.StreamWriter(Server.MapPath(file_name), False, Encoding.GetEncoding("gb2312"))
                sw.Write(strTemplate)
                sw.Close()
            Loop我准备这周结帖子,大家只要回复就有分。散分啦!
      

  2.   

    放在一个Do while循环里处理量太大了,
    建议采用分页或者多线程方式。
      

  3.   

    这么做本身就有问题,建议寻出到EXCEl中
      

  4.   

    可以告诉LZ循环4000次没有问题,我的CMS的演示网站就有2W篇文章。
    循环2W也没有故障。你已经知道用循环语句了,就差点点就能实现了,最好不要依赖人家,这样才有成就感。