1、用access建造一个数据库data.mdb,建立表guest,结构如下:
id 自动编号
标题 字符串
署名 字符串
正文 备注。
2、guest.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> |
新闻热点
疑难解答
图片精选