<%@import namespace="system.data.oledb"%>
<%@import namespace="system.data"%>
<%@import namespace="System.Web.HttpRequest"%>
<%@ Page Language="vb" debug="true" %>
<script language="vb" runat="server">
sub page_load(sender as object,e as eventargs)

if session("username")="" then
response.redirect("bbs_login.aspx")
end if
dim username as string=session("username")
dim userhead as string=session("userhead")

dim ds as dataset=new dataset
dim conn as oledbconnection
conn=new oledbconnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source="&server.mappath("db\bbs.mdb"))
dim mycommand as oledbDataAdapter
dim flage as string="subject"
mycommand=new oledbDataAdapter("select * from content where flage='"+flage+"' order by id desc",conn)
conn.open()
mycommand.fill(ds)
mydatagrid.datasource=new dataview(ds.tables(0))
mydatagrid.databind()
 end sub'======分页显示1==
sub change_page_index(sender as object,e as datagridpagechangedeventargs)
mydatagrid.currentpageindex=e.newpageindex
mydatagrid.databind()
end sub
</script>
 <html>
 <head>
 <style>
a{ 
           font: 8pt verdana;
           color:black}
a:hover{ 
           font: 8pt verdana; 
           color:#999999}
           </style>
 </head>
 <body style="margin-top:0">
<!--#include virtual="head.inc"-->
<div  align=center>
 <form runat=server>
<a href="bbs_addnew.aspx"><img src=image\post.gif border=0></a>
<asp:DataGrid
        ID="mydatagrid"
        runat="server"
        width="770"
        align="center"  
        CellPadding=4
        CellSpacing=0
        AllowPaging=True
        PagerStyle-Mode=NumericPages
        PagerStyle-HorizontalAlign=Right
        PageSize=12
        OnPageIndexChanged="change_page_index"        
        HeaderStyle-BackColor="#94CBFF"
        autogeneratecolumns="False"
        BorderWidth="1"
        style="font-size:9pt"
        BorderColor="black"> 
  <Columns>
   <asp:TemplateColumn
    ItemStyle-HorizontalAlign=Center>
   <ItemTemplate>
   <img src="image\folder.gif">
   </ItemTemplate>
   </asp:TemplateColumn>
   <asp:HyperLinkColumn
datanavigateurlfield="id"
DataNavigateUrlFormatString="bbs_view.aspx?id={0}"
DataTextField="subject"
 HeaderText="主题"
    Target=_blank
    ItemStyle-BackColor=#F7FBFF
    ItemStyle-font-name="verdana"/>
    <asp:boundcolumn
          DataField="subname"
          HeaderText="作者"
          ItemStyle-BackColor=#F7FBFF
          ItemStyle-font-name="verdana"/>
   <asp:boundcolumn
          DataField="subdate"
          HeaderText="发表时间"
          ItemStyle-BackColor=#F7FBFF
          ItemStyle-font-name="verdana"/>
           
  <asp:boundcolumn
          DataField="replynum"
          HeaderText="回复"
          ItemStyle-BackColor=#F7FBFF
          ItemStyle-font-name="verdana"
          ItemStyle-Width=25 />
  <asp:boundcolumn
          DataField="hitnum"
          HeaderText="点击"
          ItemStyle-BackColor=#F7FBFF
          ItemStyle-font-name="verdana"
          ItemStyle-Width=25/>
  </Columns>
</asp:DataGrid>
</form>
</div>
<!--#include virtual="foot.inc"-->
</body>

解决方案 »

  1.   

    <%@import namespace="system.data.sqlclient"%>
    <%@import namespace="system.data.oledb"%>
    <%@import namespace="system.data"%>
    <%@ Page Language="vb" debug="true" %>
    <body>
    <!--#include virtual="head.inc"-->
    <script language=vb runat=server>
    sub Addnew_Subject_Submit(sender as object,e as eventargs)
        '=============上传图片===============================
    dim i as integer
    dim finfo as string
    dim img as string
    dim postedfile as httppostedfile=request.files(I)
    '================================================
    if postedfile.contentlength>0 then
    dim filesplit() as string=split(postedfile.filename,"\")
    dim filename as string=filesplit(filesplit.length-1)
    postedfile.saveas(server.mappath("db")&"\"&filename)
    dim imgpath as string ="db\"&filename
    img="<img src="+imgpath+" border=0>"
    end if
    '=======================================提交文本信息==
    dim mycommand as OLEDBcommand
        dim conn as OLEDBconnection
    dim updatestring as string
    dim subjectstr as string=subject.text
    dim flage as string="subject"
       dim description as string=text1.text
       dim username as string=session("username")
      dim userhead as string=session("userhead")
       
       '================格式转换======================
        subjectstr=subjectstr.Replace("&","&amp;")
    subjectstr=subjectstr.Replace("<","&lt;")
    subjectstr =subjectstr.Replace(">","&gt;")
    subjectstr =subjectstr.Replace(chr(32),"&nbsp;")
    subjectstr =subjectstr.Replace("'","’")
    subjectstr=subjectstr.Replace(chr(13),"<br>")
    subjectstr=subjectstr.Replace(chr(10),"<br>")

    '================格式转换======================
    dim contentstr as string=content.text
        contentstr=contentstr.Replace("&","&amp;")
    contentstr=contentstr.Replace("<","&lt;")
    contentstr =contentstr.Replace(">","&gt;")
    contentstr =contentstr.Replace(chr(32),"&nbsp;")
    contentstr =contentstr.Replace("'","’")
    contentstr=contentstr.Replace(chr(13),"<br>")
    contentstr=contentstr.Replace(chr(10),"<br>")
    '============
    description=description.Replace("&","&amp;")
    description=description.Replace("<","&lt;")
    description =description.Replace(">","&gt;")
    description=description.Replace(chr(32),"&nbsp;")
    description=description.Replace("'","’")
    description=description.Replace(chr(13),"<br>")


    '=====================将转换后的字符串保存到数据库===
    if username="" then
    username="未知"
    end if
    updatestring="insert into content (subject,content,subdate,flage,subname,headimg,hitnum,replynum,img,imgdescription)values('"+subjectstr+"','"+contentstr+"',NOW(),'"+flage+"','"+username+"','"+userhead+"',0,0,'"+img+"','"+description+"')"
    conn=new OLEDBconnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source="&server.mappath("db\bbs.mdb"))
        mycommand=new OLEDBcommand(updatestring,conn)
        conn.open()
        mycommand.executenonquery()
       response.redirect("bbs.aspx")
    end sub
    sub reset_form(sender as object,e as eventargs)
    subject.text=""
    content.text=""
    end sub
    </script>
    <form enctype="multipart/form-data" runat=server ID="Form1" style="font-size:9pt" >
      文章标题:<asp:textbox ID="SUBJECT" runat="server"  TextMode="SingleLine"  MaxLength=30 size=30/><br>
      文章内容:<ASP:TEXTBOX  ID="content"   runat="server"  textmode="multiline" rows="10" Columns="60"/>
    <br>
    上传图片:<input type=file id=fileup1 runat=server  SIZE=50 maxlength=50><br>
        图片说明:<asp:textbox id=text1 runat=server textmode=singleline maxlength=30 size=30/><asp:Panel ID="button_panel" runat="server"  HorizontalAlign="left"><br>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<asp:button ID="submit" runat="server" OnClick="Addnew_Subject_Submit" Text="发表这篇文章"/>
     
    </asp:Panel>
    <asp:Label ID="statues" Runat="server"></asp:Label>
    <asp:RequiredFieldValidator
     ID="REVPASSWORD"
      ControlToValidate="subject"
       Display=None
        InitialValue=""
         ErrorMessage="文章名必须填写!"
          Runat=server>
           </asp:RequiredFieldValidator>
    <asp:RequiredFieldValidator
     ID="Requiredfieldvalidator1"
      ControlToValidate="content"
       Display=None
        InitialValue=""
         ErrorMessage="文章内容必须填写!"
          Runat=server>
           </asp:RequiredFieldValidator>
           <asp:ValidationSummary
      ID="ValidationSummary1"
       Runat=server
           EnableViewState=False
            ShowSummary=False
          HeaderText="文章提交失败,请注意以下规则:"
           ShowMessageBox=True
            Font-Name=verdana
             Font-Size=9pt>
             </asp:ValidationSummary>
    </form>
    <!--#include virtual="foot.inc"-->
    </body>
      

  2.   

    <%@import namespace="system.data.sqlclient"%>
    <%@import namespace="system.data.OLEDB"%>
    <%@import namespace="system.data"%>
    <%@ Page Language=vb debug=true %>
    <script language="vb" runat="server">
    sub reply_subject(sender as object,e as eventargs)
    '=============上传图片===============================
    dim i as integer
    dim finfo as string
    dim img as string
    dim postedfile as httppostedfile=request.files(I)
    '================================================
    if postedfile.contentlength>0 then
    dim filesplit() as string=split(postedfile.filename,"\")
    dim filename as string=filesplit(filesplit.length-1)
    postedfile.saveas(server.mappath("db")&"\"&filename)
    dim imgpath as string ="db\"&filename
    img="<img src="+imgpath+" border=0>"
    end if
    '== 文本信息==
    dim mycommand as OLEDBcommand
    dim conn as OLEDBconnection
    dim updatestring as string
    dim subjectstr as string=reply.text
    dim subj as string=subject_name.text
    dim flage as string="reply"
    dim description as string=text1.text
    dim username as string=session("username")
    dim userhead as string=session("userhead")
    dim replystr as string=request.querystring("id")
       '================格式转换======================
        subjectstr=subjectstr.Replace("&","&amp;")
    subjectstr=subjectstr.Replace("<","&lt;")
    subjectstr =subjectstr.Replace(">","&gt;")
    subjectstr =subjectstr.Replace(chr(32),"&nbsp;")
    subjectstr =subjectstr.Replace("'","’")
    subjectstr=subjectstr.Replace(chr(13),"<br>")
    '======================
    '================格式转换======================
        subj=subj.Replace("&","&amp;")
    subj=subj.Replace("<","&lt;")
    subj =subj.Replace(">","&gt;")
    subj =subj.Replace(chr(32),"&nbsp;")
    subj =subj.Replace("'","’")
    subj=subj.Replace(chr(13),"<br>")
    '====================================
    description=description.Replace("&","&amp;")
    description=description.Replace("<","&lt;")
    description =description.Replace(">","&gt;")
    description=description.Replace(chr(32),"&nbsp;")
    description=description.Replace("'","’")
    description=description.Replace(chr(13),"<br>")

    '=====================将转换后的字符串保存到数据库===
    if username="" then
    username="未知"
    end if
    updatestring="insert into content(subject,content,subdate,flage,subname,headimg,reply,img,imgdescription)values('"+subj+"','"+subjectstr+"',NOW(),'"+flage+"','"+username+"','"+userhead+"','"+replystr+"','"+img+"','"+description+"')"
    conn=new OLEDBconnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source="&server.mappath("db\bbs.mdb"))
        mycommand=new OLEDBcommand(updatestring,conn)
        conn.open()
        mycommand.executenonquery()
        '=================================回复数加一--------------
        dim mycommand2 as OLEDBcommand=new OLEDBcommand("update content set replynum=replynum+1 where id="&CINT(request.querystring("id")),conn)
        mycommand2.executenonquery() 
        conn.close()
        subject_name.text=""
        reply.text=""
        response.redirect ("bbs_view.aspx?id="&request.querystring("id"))'===============================================================================================================
    end sub
    </script>
    <body bgcolor=white>
    <!--#include virtual="head.inc"-->
    <form enctype="multipart/form-data" runat=server ID="Form1" style="font-size:9pt" >
      文章标题:<asp:textbox ID="subject_name" runat="server"  TextMode="SingleLine"  MaxLength=30 size=30/>
    <br>
      文章内容:<ASP:TEXTBOX  ID="reply"   runat="server"  textmode="multiline" rows="10" Columns="60"/>
    <br>
    上传图片:<input type=file id=fileup1 runat=server  SIZE=50 maxlength=50><br>
        图片说明:<asp:textbox id=text1 runat=server textmode=singleline maxlength=30 size=30/>
    <p align=center><asp:Button Text="   提交   "  style="font-sizE:9pt" ID="reply_button" Runat=server OnClick="reply_subject"/></p>
    <asp:RequiredFieldValidator
      Runat=server
           Display=None
          ID="Requiredfieldvalidator2"
           ErrorMessage="文章标题必须填写!"
            ControlToValidate=subject_name>
            </asp:RequiredFieldValidator><asp:RequiredFieldValidator
      Runat=server
           Display=None
          ID=RequiredFieldValidator1
           ErrorMessage="文章内容必须填写!"
            ControlToValidate=reply>
            </asp:RequiredFieldValidator>
     <asp:ValidationSummary
       Runat=server
        ShowSummary=False
         EnableViewState=False
        ID=ValidationSummary1
              ShowMessageBox=True
              Font-Name=verdana
             Font-Size=9pt>
           </asp:ValidationSummary>       
    </form>
    <!--#include virtual="foot.inc"-->
    </body>
      

  3.   

    Source="&server.mappath("db\bbs.mdb")什么意思?
    是不是让它编程绝对路径?
      

  4.   

    谢谢 yellowwee(端木柒) 
    我连上去了,但是我的连接字符串是
    "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=Test1.mdb"
    这样我的数据库文件就不得不放在/winnt/system32里
    我想把数据库文件放在工程的同一目录下,该怎么写?
      

  5.   

    Server.MapPath(...)是把虚拟目录的相对路径解析成服务器对应的真实路径。
      

  6.   

    你这样写Source="&server.mappath("db\bbs.mdb")就不用放到那了!
      

  7.   

    可是这样写会报错:
    找不到类型或命名空间名称“server”(是否缺少 using 指令或程序集引用?)