如何操作Access数据库?(查询,删除,更新,增加)

 我来答
小柒17950
2013-08-26 · TA获得超过108个赞
知道答主
回答量:148
采纳率:66%
帮助的人:67.3万
展开全部
powered by 25175.net如何操作Access数据库? 一、查找记录find.htm<HTML><HEAD><TITLE> Access数据库记录查找</TITLE></HEAD><BODY><FORM ACTION="find.asp" METHOD="POST" id=form1 name=form1> 请输入您要查找的人的姓名: <BR> <INPUT TYPE="TEXT" NAME="man" SIZE=50><BR><BR> <INPUT TYPE="submit" NAME="send" VALUE="他/她的id是多少?"></FORM></BODY></HTML>find.asp<% Option Explicit%><!-- METADATA TYPE="typelib" FILE="C:\Program Files\Common Files\System\ado\msado15.dll" --><HTML><BODY><% Dim strman, strfind , objConn strman = Request.Form("man") Dim objRS Set objconn = Server.CreateObject("ADODB.Connection") set objRS = Server.CreateObject("ADODB.Recordset") objConn.Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("Man.mdb"))objRS.Open "Names", objConn, adOpenStatic, adLockReadOnly, adCmdTable strfind = "Name='" & strman & "'" objRS.Find strfind' 显示第一条相关记录 If objRS.EOF Then Response.Write "哦,没有找到您要查找的人!" & _ strman Else Response.Write "他/她的姓名是: " & strman & "" & _ "Id是:" & objRS("ID") & "<BR>" & _ End If objRS.Close Set objRS = Nothing objConn.Close Set objConn = Nothing%></BODY></HTML> 二、过滤记录filter.asp<% Option Explicit%><!-- METADATA TYPE="typelib" FILE="C:\Program Files\Common Files\System\ado\msado15.dll" --><HTML><HEAD><TITLE>精彩春风之Access数据库记录过滤</TITLE></HEAD><BODY> <% Dim objRS, intLetter, strChar, strCriteria objConnSet objConn = Server.CreateObject("ADODB.Connection")Set objRS = Server.CreateObject("ADODB.Recordset") objConn.Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("Man.mdb")) objRS.Open "Names", objConn, adOpenStatic, adLockReadOnly, adCmdTable For intLetter = 1 To 26 strChar = Chr(intLetter+64) strCriteria = "Title LIKE '" & strChar & "*'" objRS.Filter = strCriteria If Not objRS.EOF Then Response.Write "<H2>" & strChar & "</H2>" & _ "<TABLE BORDER=1><TR><TD><B>姓名<B></TD><TD>ID</TD></TR>" While Not objRS.EOF Response.Write "<TR><TD>" & objRS("Name") & "</TD>" & _ "<TD>" & objRS("ID") & "</TD></TR>" objRS.MoveNext Wend Response.Write "</TABLE>" End If Next objRS.Close Set objRS = NothingobjConn.Close Set objConn = Nothing%></BODY></HTML> 三、添加记录add.asp<% Option Explicit%><!-- METADATA TYPE="typelib" FILE="C:\Program Files\Common Files\System\ado\msado15.dll" --><HTML><HEAD><TITLE>精彩春风之Access数据库记录添加</TITLE></HEAD><BODY><% Dim objRS, intIDForNewRecord , objConnSet objConn = Server.CreateObject("ADODB.Connection")set objRS = Server.CreateObject("ADODB.Recordset") objConn.Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("Man.mdb"))' 连接数据库 objRS.Open "Names", objConn, adOpenStatic, adLockOptimistic, adCmdTable objRS.MoveLast intIDForNewRecord = objRS("ID") + 1 objRS.AddNew' 添加新记录 objRS("ID") = intIDForNewRecord objRS("Names") = "ManD" objRS.Update objRS.Close objRS.Open "SELECT * FROM Names WHERE ID=" & intIDForNewRecord, _ ObjConn, adOpenForwardOnly, adLockReadOnly, adCmdText If objRS.EOF Then Response.Write "噢,出错了!新记录没找到." Else Response.Write "恭喜,添加成功!新记录是:<BR> " & _ "Name = '" & objRS("Name") & "'<BR>" & _ "ID = '" & objRS("ID") & "'<BR>" End If objRS.Close Set objRS = Nothing objConn.Close' 清空 Set objConn = Nothing%></BODY></HTML>四、更新记录和上面的“添加记录”一样,只需把“添加”命令改做“更新”就可以了:objRS.Update 五、删除记录This is the asp page, we will delete the record that we added ManD:<% Option Explicit%><!-- METADATA TYPE="typelib" FILE="C:\Program Files\Common Files\System\ado\msado15.dll" --><HTML><HEAD><TITLE> Access数据库记录删除</TITLE></HEAD><BODY><% Dim objRS, intIDForNewRecord, objConnSet objConn = Server.CreateObject("ADODB.Connection")set objRS = Server.CreateObject("ADODB.Recordset") objConn.Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("Man.mdb")) objRS.Open "Names", objConn, adOpenStatic, adLockOptimistic, adCmdTable objRS.Filter = "Name = ' ManD'" Response.Write "注意,以下记录将被删除:<BR> " While Not objRs.EOF Response.Write objRS("ID") & "<BR>" objRS.Delete objRS.MoveNext Wend objRS.Close Response.Write "<BR>核实删除记录:<BR>" objRS.Open "SELECT * FROM Names WHERE Name LIKE 'ManD'", _ objConn, adOpenForwardOnly, adLockReadOnly, adCmdText If objRS.EOF Then Response.Write "ManD的所有记录都已被从数据库删除!<BR> " Else Response.Write "噢,删除失败!ManD的记录还在数据库里呢, " & _ "ID=" & objRS("ID") End If objRS.Close Set objRS = Nothing objConn.Close Set objConn = Nothing%></BODY></HTML>
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式