Instance programming: Writing a message book with asp.net and access

Source: Internet
Author: User
Tags net access

 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>



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.