数据库

位置:IT落伍者 >> 数据库 >> 浏览文章

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


发布日期:2021年05月12日
 
实例编程:用ASP.Net和Access编写留言本
用Access建造一个数据库datamdb建立表Guest结构如下:

ID 自动编号

标题 字符串

署名 字符串

正文 备注

guestaspx


<%@ Import Namespace=SystemData %>

<%@ Import Namespace=SystemDataOleDb %>

<html><head>

<style>

<!

body{fontsize:pt}

p{fontsize:pt}

td{fontsize:pt}

//>

</style>

<title>留言本</title></head>

<body>

<p align=right><font size=>留言本</font></p>

<script language=vb runat=server>

Sub Page_Load(Source As Object E As EventArgs)

Dim myConn As New OleDbConnection(Provider=MicrosoftJetOLEDB ;Data Source= & servermappath(datamdb))

Dim myAdapter As New OleDbDataAdapter

Dim myOleDbCommandBuilder As OleDbCommandBuilder = New OleDbCommandBuilder(myAdapter)

Dim DS As DataSet = New DataSet

myAdapterSelectCommand = new OleDbCommand(select ID 标题 署名 from Guest order by id desc myconn)

myconnopen()

myAdapterFill(ds Guest)

mlDataSource=dsTables(Guest)DefaultView

mlDataBind()

end sub

</script>

<ASP:DataGrid id=ml runat=server

Width=%

BorderColor=black

ShowFooter=false

CellPadding=

CellSpacing=

FontName=宋体

FontSize=pt

HeaderStyleBackColor=#ddaacc

EnableViewState=false

>

<Columns>

<asp:HyperLinkColumn

DataNavigateUrlField=id

DataNavigateUrlFormatString=seeasp?id={}

text=See!

Target=_new

/>

</Columns>

</asp:DataGrid>

<br><br><font size=>我要留言</font><br>

<form method=post action=sendaspx>

标题:<input type=text name=title><br>

署名:<input type=text name=name><br>

内容:<textarea name=body></textarea><br>

<input type=submit>

</form>

sendaspx

<%@ Import Namespace=SystemData %>

<%@ Import Namespace=SystemDataOleDb %>

<script language=vb runat=server>

Sub Page_Load(Source As Object E As EventArgs)

Dim myConn As New OleDbConnection(Provider=MicrosoftJetOLEDB ;Data Source= & servermappath(datamdb))

Dim myInsertQuery As String = insert into guest (标题 署名 内容) values (@# & request(title) & @# @# & request(name) & @# @# & request(body) & @#)

Dim myOleDbCommand As New OleDbCommand(myInsertQuery)

myOleDbCommandConnection = myConn

myConnOpen()

myOleDbCommandExecuteNonQuery()

myOleDbCommandConnectionClose()

responseredirect(guestaspx)

end sub

</script>

seeasp(显示单个数据不如用ASP)

<html><head>

<style>

<!

body{fontsize:pt}

p{fontsize:pt}

td{fontsize:pt}

//>

</style>

<title>察看留言</title></head>

<body>

<p align=right><font size=>察看留言</font></p>

<%

id=request(id)

set cn=servercreateobject(ADODBCONNECTION)

cnopen DBQ= + servermappath(datamdb) + ;DefaultDir=; DRIVER={Microsoft Access Driver (*mdb)};

set rs=servercreateobject(adodbrecordset)

rsopen select * from guest where id= & id cn

%>

ID:<% = id %><BR>

标题:<% = rs(标题) %><br>

署名:<% = rs(署名) %><br>

内容:<Br><% = rs(内容) %><br>

<a >返回</a>

上一篇:Entity Framework数据转换层通用类

下一篇:dOOdad提供的数据绑定、特殊函数和事务处理