1, the use of access to build a database data.mdb, the establishment of table guest, the structure is as follows:
ID Auto Number
Title string
Signature string
Body notes.
2, Guest.aspx
<%@ Import namespace= "System.Data"%> <%@ Import namespace= "System.Data.OleDb"%> <style> <!-- BODY{FONT-SIZE:9PT} P{FONT-SIZE:9PT} TD{FONT-SIZE:9PT} --> </style> <title> Message Book </title><body> <p align=right><font size=6> Message book </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;D ata 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, title, signature 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= "Song Body" 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> I want to leave a message </font><br> <form Method=post action=send.aspx> Title: <input Type=text name=title><br> Signature: <input Type=text name=name><br> Content: <textarea name=body></textarea><br> <input type=submit> </form> |
3, Send.aspx
< %@ 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=microso Ft. jet.oledb.4.0;D ata source= "& Server.MapPath (" Data.mdb ")) Dim myinsertquery as String =" INSERT INTO Guest (title, signature, content) 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 (display a single data rather than using ASP)
<style> <!-- BODY{FONT-SIZE:9PT} P{FONT-SIZE:9PT} TD{FONT-SIZE:9PT} --> </style> <title> View Message </title><body> <p align=right><font size=6> View message </font></p> <% Id=request ("id") Set Cn=server.createobject ("ADODB. CONNECTION ") Cn.open "dbq=" + Server.MapPath ("Data.mdb") + ";D efaultdir=; Driver={microsoft Access DRIVER (*.mdb)}; Set Rs=server.createobject ("Adodb.recordset") Rs.Open "SELECT * from guest where id=" & ID, CN %> id:<% = ID%><br> Title: <% = rs ("title")%><br> Signature: <% = rs ("signature")%><br> Content: <br><% = rs ("content")%><br> <a href= "guest.aspx" > Return </a> |