想不想get新技能酷炫一下,今天图老师小编就跟大家分享个简单的实例编程:用ASP.Net和Access编写留言本教程,一起来看看吧!超容易上手~
【 tulaoshi.com - Web开发 】
1、用Access建造一个数据库data.mdb,建立表Guest,结构如下:
ID 自动编号
标题 字符串
署名 字符串
正文 备注。
2、guest.aspx
%@ Import Namespace="System.Data" %
%@ Import Namespace="System.Data.OleDb" %
htmlhead
style
!--
body{font-size:9pt}
p{font-size:9pt}
td{font-size:9pt}
//--
/style
title留言本/title/head
body
p align=rightfont 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
brbrfont size=5我要留言/fontbr
form method=post action=send.aspx
标题:input type=text name=titlebr
署名:input type=text name=namebr
内容:textarea name=body/textareabr
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)
htmlhead
style
!--
body{font-size:9pt}
p{font-size:9pt}
td{font-size:9pt}
//--
/style
title察看留言/title/head
body
p align=rightfont 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
来源:http://www.tulaoshi.com/n/20160219/1606208.html
看过《实例编程:用ASP.Net和Access编写留言本》的人还看了以下文章 更多>>