实例编程:用ASP.Net和Access编写留言本

时间:2008-10-07 11:56:25  来源:第二电脑网上收集  作者:

  第二电脑网导读:ong>2、guest.aspx  <%@ Import Namesp...
  正文:

 1、用Access建造一个数据库data.mdb,建立表Guest,结构如下:

  ID 自动编号
  标题 字符串
  署名 字符串
  正文 备注。

  2、guest.ASP/ target=_blank class=infotextkey>aspx


 <%@ Import Namespace="System.Data" %>
  <%@ Import Namespace="System.Data.OleDb" %>
  <html><head>
  <style>
  <!--
  body{font-size:9pt}
  p{font-size:9pt}
  td{font-size:9pt}
  //-->
  </style>
  <title>留言本</title></head>
  <body>
  <p align=right><font size=6>留言本</font></p>
  <script language=vb runat=server>
  Sub Page_Load(Source As Object, E As EventArgs)
   Dim myConn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0 ;Data Source=" & server.mappath("data.mdb"))
   Dim myAdapter As New OleDbDataAdapter
   Dim myOleDbCommandBuilder As OleDbCommandBuilder = New OleDbCommandBuilder(myAdapter)
   Dim DS As DataSet = New DataSet
   myAdapter.SelectCommand = new OleDbCommand("select ID, 标题, 署名 from Guest order by id desc", myconn)
   myconn.open()
   myAdapter.Fill(ds, "Guest")
   ml.DataSource=ds.Tables("Guest").DefaultView
   ml.DataBind()
  end sub
  </script>
   <ASP:DataGrid id="ml" runat="server"
   Width="100%"
   BorderColor="black"
   ShowFooter="false"
   CellPadding=3
   CellSpacing="0"
   Font-Name="宋体"
   Font-Size="9pt"
   HeaderStyle-BackColor="#ddaacc"
   EnableViewState="false"
   >
  <Columns>
   <asp:HyperLinkColumn
   DataNavigateUrlField="id"
   DataNavigateUrlFormatString="see.asp?id={0}"
   text="See!"
   Target="_new"
   />
  </Columns>
  
  </asp:DataGrid>
  <br><br><font size=5>我要留言</font><br>
  <form method=post action=send.aspx>
  标题:<input type=text name=title><br>
  署名:<input type=text name=name><br>
  内容:<textarea name=body></textarea><br>
  <input type=submit>
  </form> 

    3、send.aspx

  <%@ Import Namespace="System.Data" %>
  <%@ Import Namespace="System.Data.OleDb" %>
  <script language=vb runat=server>
  Sub Page_Load(Source As Object, E As EventArgs)
   Dim myConn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0 ;Data Source=" & server.mappath("data.mdb"))
   Dim myInsertQuery As String = "insert into guest (标题, 署名, 内容) values (@#" & request("title") & "@#, @#" & request("name") & "@#, @#" & request("body") & "@#)"
   Dim myOleDbCommand As New OleDbCommand(myInsertQuery)
   myOleDbCommand.Connection = myConn
   myConn.Open()
   myOleDbCommand.ExecuteNonQuery()
   myOleDbCommand.Connection.Close()
   response.redirect("guest.aspx")
  end sub
  </script>  

  4、see.asp(显示单个数据不如用ASP)

  <html><head>
  <style>
  <!--
  body{font-size:9pt}
  p{font-size:9pt}
  td{font-size:9pt}
  //-->
  </style>
  <title>察看留言</title></head>
  <body>
  <p align=right><font size=6>察看留言</font></p>
  <%
  id=request("id")
  set cn=server.createobject("ADODB.CONNECTION")
  cn.open "DBQ=" + server.mappath("data.mdb") + ";DefaultDir=; DRIVER={Microsoft Access Driver (*.mdb)};"
  set rs=server.createobject("adodb.recordset")
  rs.open "select * from guest where id=" & id , cn
  %>
  ID:<% = id %><BR>
  标题:<% = rs("标题") %><br>
  署名:<% = rs("署名") %><br>
  内容:<Br><% = rs("内容") %><br>
  <a href="guest.aspx">返回</a>

(负责编辑:周洁)
实例编程:用ASP.Net和Access编写留言本》由第二电脑网原创提供,转载请注明:http://www.002pc.com/master/College/Programming/ASP/2008-10-07/2719.html


关键字:

关于《实例编程:用ASP.Net和Access编写留言本》文章的评论

站内搜索: 高级搜索

热门搜索: Windows style 系统 tr IP QQ CPU 安装 function 注册 if td