用ASP如何读取ACCESS数据库中的某个字段?[要代码哦]

ASP \u5982\u4f55\u8bfb\u53d6ACCESS\u6570\u636e\u5e93\u7684\u5b57\u6bb5\u7c7b\u578b\uff01\uff01\uff1f

ASP\u5148\u521b\u5efa\u4e00\u4e2aadodb.Rrcorddest\u5bf9\u8c61,\u6bd4\u5982set rs=server.createobject("adodb.Rrcorddest")
SQL="sql\u8bed\u53e5"
\u7136\u540ers.open sql
\u518d\u7528\u4e00\u4e2a\u5faa\u73af\u547d\u4ee4
if not rs.eof then
rs.movefirst
do while not rs.eof
for i=0 to rs.fields.count
response.write (rs.fields(i).type)//\u8fd9\u4e2a\u5c31\u662f\u5199\u51fa\u5b57\u6bb5\u7684\u7c7b\u578b\u4e86
next
rs.movenext
loop
end if
\u662f\u8fd9\u6837\u7684 type\u786e\u5b9e\u5b57\u6bb5\u7c7b\u578b
\u4e0d\u8fc7\u4ed6\u662f\u4ee5\u6570\u5b57\u6765\u8bf4\u660e\u7684
\u6bd4\u5982\u5728SQL\u91cc 200\u4ee3\u8868varchar
129\u4ee3\u8868char
11\u4ee3\u8868Bit(1\u62160\u7684\u6574\u6570\u6570\u636e)
\u6240\u4ee5\u4f60\u60f3\u663e\u793a\u4f60\u90a3\u6837\u7684\u7ed3\u679c\u5c31\u5148\u5f97\u4e86\u89e3TYPE\u663e\u793a\u7684\u76f4\u4ee3\u8868\u4ec0\u4e48\u7c7b\u578b
\u7136\u540e\u7528if\u8bed\u53e5
if(rs.fields(i).type=200) then
response.write("varchar")
end if

\u9996\u5148\u5168\u90e8\u53d6\u56de\u5185\u5bb9\uff0c\u6bd4\u5982content=rs("content")
\u56fe\u7247\u662f\u5305\u542b\u5728\u91cc\u9762\u7684\uff08\uff09,\u7528\u5207\u5272\u51fd\u6570\u5c06\u5185\u5bb9\u5207\u5272\uff0c\u5c31\u4ee5>\u53f7\u5207\u5272\uff1acontent=split(content,">")
\u7136\u540e\u5207\u5272\u7684\u7b2c0\u90e8\u5206\u662f\u56fe\u7247\uff0c\u6211\u4eec\u8981\u7b2c1\u90e8\u5206\uff1acontent=content(1),\u6700\u540e\u53d6\u56de\u524d50\u4e2a\u5b57\u7b26\uff1acontent=Left(content,50)

\u54e6\uff0c\u662f\u8fd9\u6837\u554a\uff0c\u90a3\u5c31\u8fd9\u6837\uff0c\u6765\u81ea\u5199\u4e00\u4e2a\u51fd\u6570

<%
Function guo(a)
a=Lcase(a) '\u5c06\u5b57\u7b26\u8f6c\u6362\u4e3a\u5c0f\u5199
for i=0 to 132
a=Replace(a,Chr(i),"")
next
a=Left(a,50)
guo=a
End Function
%>
\u5c06\u8fd9\u4e2a\u51fd\u6570\u653e\u5230\u6587\u4ef6\u6700\u9876\u90e8\uff0c\uff08\u5982\u679c\u6709\u670d\u52a1\u5668\u7aef\u5305\u62ec\u4ee3\u7801\u5c31\u653e\u5230\u8fd9\u4e2a\u4ee3\u7801\u7684\u4e0b\u9762\uff09\uff0c\u8c03\u7528\u65b9\u6cd5\uff1a\u4f8b\u5982\uff1a

content=guo(rs("content"))

\u4f60\u6ca1\u7528\u4f7f\u7528\u6211\u7ed9\u4f60\u5199\u7684\u51fd\u6570\uff1f
\u6211\u8fd9\u4e2a\u51fd\u6570\u5c31\u662f\u5c06\u5185\u5bb9\u4e2d\u7684\u9664\u4e86\u4e2d\u6587\u6c49\u5b57\uff0c\u5176\u4ed6\u7684\u5168\u90e8\u8fc7\u6ee4\u6389\u7684\u554a\uff0c\u600e\u4e48\u8fd8\u4f1a\u6709\u4f60\u8bf4\u7684onload="javascript:if(this.width>screen.width-350)this.width=screen.width-350">\u3002\u3002\u3002\u5462\uff1f

首先连接数据库,然后:

<%
Set Rs = Server.CreateObject("ADODB.RecordSet") '创建一个对象
SQL = "Select 作者字段名 From [表1]" '查询表1中的作者字段
Rs.Open SQL,Conn,1,1 '执行查询
Do While Not Rs.Eof '开始循环显示
Response.Write Rs("作者字段名") '显示查询出的字段名下的内容
Response.Write "<br>" '显示一次输出一个回车来换行(便于查看)
Rs.MoveNext '开始输出下一条内容
Loop '结束循环
Set Rs = Nothing '关闭创建的对象
%>

建立access的数据库news,还有表news,表的字段(id,title),id唯一,输入数据保存,用下面代码可查询,可分页
-----------------------下面保存为search.asp--------------------------
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>文件</title>
</head>
<body bgcolor="#ffffff">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<script>
function btn_ck_bh_Click()
{
var cx = document.form1.cxsj.value;
form1.action ="search.asp?cx="+cx;
}
</script>
<table border="1" cellspacing="0" bgcolor="#F0F8FF" bordercolorlight="#4DA6FF" bordercolordark="#ECF5FF" width="88%" style="word-break:break-all">
<tr>
<td width="778" align="center" colspan="7">
<form method="POST" name="form1" action=search.asp>
<p>输入搜索内容:<input type="text" name="cxsj" size="20"><input type="submit" value="提交" name="B1" LANGUAGE="javascript" onclick="btn_ck_bh_Click()">
<input type="reset" value="重写" name="B2"></p>
</form>
</td>
</tr>
</table>
<table border="1" cellspacing="0" bgcolor="#F0F8FF" bordercolorlight="#4DA6FF" bordercolordark="#ECF5FF" width="88%" style="word-break:break-all">
<tr>
<td width="8%" align="center"><strong><font color="#0080C0">ID 号</font></strong></td>
<td width="58%" align="center"><strong><font color="#0080C0">标 题</font></strong></td>
<td width="8%" align="center"><strong><font color="#0080C0">修 改</font></strong></td>
<td width="8%" align="center"><strong><font color="#0080C0">删 除</font></strong></td>
</tr>
<%
'数据库查询
'获得搜索内容
cx = request("cx")
dim pageCount
'把page转换成整数
page = cint(request("page"))
set conn=server.createobject("adodb.connection")'
set rs=server.createobject("adodb.recordset")
conn.open "DBQ=" & server.mappath("./news.mdb") & ";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"

' 获取产品的名字记录集(从 news表中)
if cx <> "" then
sql = "select * from news where title like '%"&cx& "%' order by id desc"
else
sql ="select * from news order by id desc"
end if
rs.open sql,conn,3,3
'如果没有数据记录
if rs.bof then
errmsg=errmsg+"<br>"+"<li>"+keyword+"没有记录,请返回!!"
response.write errmsg
response.end
end if

' 设置记录集在每页的总行数,也就是 PageSize属性
RS.PageSize=40
'把rs.pageCount转换成整数和page才能作比较
pageCount = cint(rs.pageCount)
' 设置当前的页号( AbsolutePage属性)
if page = 0 then
page =1
end if
RS.AbsolutePage = page
x=1
' 显示当前页中的所有记录( PageSize中设置的行数)

WHILE NOT RS.EOF AND NumRows<RS.PageSize
%>
<tr onmouseover="this.bgColor='#99ccff'" onmouseout="this.bgColor=''">
<td width="8%"><p align="center"><%=rs("id")%></td>
<td width="58%"><a href="view.asp?id=<%=rs("id")%>" target="_blank"><%=rs("title")%></a></td>
<td width="8%" align="center"><a href="edit.asp?id="<%=rs("id")%>>修 改</a></td>
<td width="8%" align="center"><a href="delet.asp?id="<%=rs("id")%>>删 除</a></td>
</tr>
<%RS.MoveNext
NumRows=NumRows+1
WEND%>
<tr onmouseover="this.bgColor='#99ccff'" onmouseout="this.bgColor=''">
<td width="105%" align="center" colspan="6"> </td> </tr>
<tr>
<td width="105%" align="center" colspan="6">
<p align="center"><FONT color=#333333>共<%=PageCount%>页 第<%=page%>页★
<%if page=1 then%>首页<%end if%>
<%if page>1 then%>
<A HREF="search.asp?page=1&cx=<%=cx%>"> 首页</A>
<%end if%>★
<%if page>1 then%><A HREF="search.asp?page=<%=page-1%>&cx=<%=cx%>"><%end if%>上一页</a>
<%
dim pagewhere
dim p
p = 1
'把pagewhere转换成整数
'pagewhere = cint(request("pagewhere"))
pagewhere = pageCount
if pagewhere>0 then
for p=1 to pagewhere
if p <> page then%>
<A HREF="search.asp?page=<%=p%>&cx=<%=cx%>"><%=p%></a>
<%end if
if p =page then%>
<%=p%>
<% end if
next
end if%>
<%if page < PageCount then%>
<A HREF="search.asp?page=<%=page+1%>&cx=<%=cx%>">
<%end if %>下一页</A>★
<%if page=PageCount then%>尾页
<%end if%>
<%if page<PageCount then%>
<A HREF="search.asp?page=<%=PageCount%>&cx=<%=cx%>"> 尾页</A>
<%end if%>
</p></FONT></td> </tr> <tr>
<td width="105%" align="center" colspan="6">搜索内容:<%=cx%></td>
</tr>
</table></center></div>
</body></html>
<%
rs.close
Set rs=nothing
conn.close
set conn=nothing
%>

就一句
Select 你想要的字段名 From 表名
如果要屏蔽重复行的话在后面加上 Group By 你想要的字段名
如果想排序的话就在后面加上 Order By 你想要的字段名 ASC升序,DESC降序

  • ASP濡備綍瀹炵幇璇诲彇骞朵笖鏄剧ずACCESS?
    绛旓細棣栧厛閾炬帴鏁版嵁搴 dataaccess = server.mappath("data/xxxx.mdb")'杩炴帴OLEDB Set oConn = Server.CreateObject("ADODB.CONNECTION")oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dataaccess 鍏舵鎵撳紑琛ㄥ苟璇诲彇璁板綍 sql = "select top 100 * from [tablebb] where 1=1"Set oRs ...
  • asp濡備綍鑾峰彇access鏁版嵁搴撶殑鏁版嵁??璇烽珮鎵嬫寚鏁
    绛旓細sql="select*from tablename where data=data"銆'绗簩涓猟el涓轰綘鎯宠鏌ヨ鐨勬暟鎹,涔熷彲涓哄涓紝鐢ㄢ滐紝鈥濆彿鍒嗗紑 rs.open sql,conn,1,1 if rs.eof and rs.bof then response.write "鏁版嵁涓嶅瓨鍦"else rs.delete response.write rs("data")銆'濡傛灉鏈夊涓浉鍚岀殑鏁版嵁锛岃繖鍙敤for 鈥︹ext 寰幆璇彞 ...
  • 鐢╝sp鎬庢牱鎸夐『搴璇诲彇access鏁版嵁搴撲腑1鍒100涔嬮棿鐨勬暟鍊,姹傝缁嗕唬鐮乢鐧惧害...
    绛旓細鐢╝sp鎬庢牱鎸夐『搴璇诲彇access鏁版嵁搴撲腑1鍒100涔嬮棿鐨勬暟鍊硷紝姹傝缁嗕唬鐮 < dim db,str,sql,rs set db=createobject("adodb.connection")str="Dbq="&server.mappath("鏁版嵁搴撶浉瀵硅矾寰")&";Driver={Microsoft Access Driver (*.mdb)};"db.open str sql="select top 100 from 琛ㄥ悕"set rs=db.execute(...
  • 鐢╝sp璇诲彇銆佷慨鏀广佸垹闄access鏁版嵁搴鐨勬暟鎹
    绛旓細dotype=request("dotype")id=request("id")Set cn = Server.CreateObject("ADODB.Connection")cn.Open "dbq=" & server.MapPath("Sys_V1x.mdb") & ";driver={microsoft access driver (*.mdb)};"set rs = server.createobject("adodb.recordset")if dotype="" then'璇诲彇 rs.open "select...
  • 鐢╝sp鎬庝箞鏌ヨaccess涓殑鏁版嵁,鍦ㄦ柊鐨勯〉闈㈤噷鏄剧ず
    绛旓細conn.open ConnString '鏂板缓鏁版嵁搴撹繛鎺 set rs=server.createobject("adodb.recordset") '鏂板缓璁板綍闆 rs.open "select * from zw ",conn,1,1 '鎵撳紑鏁版嵁琛 if rs.bof and rs.eof then '鏁版嵁璁板綍涓虹┖,閭d箞鏄剧ず!response.write "璁板綍涓虹┖"response.end else '鍚﹀垯,涓鐩村惊鐜緭鍑!do while no...
  • ASP鎬庢牱璁块棶access鏁版嵁搴鐨勬暟鎹
    绛旓細Conn.Open "Provider=Microsoft.Jet.Oledb.4.0;DataSource="&Server.MapPath("璺緞/鏁版嵁搴.mdb")鐒跺悗灏卞彲浠ユ搷浣滄暟鎹簱鐨勬煡璇 淇敼 娣诲姞 鏇存柊绛 濡傦細sql="select * from 琛"set rs=server.creatObject("adodb.recordset")rs.open sql,conn,1,1 do while not rs.eof response.write rs(0)&"br...
  • 濡備綍asp鏌ヨACCESS涓殑鏁版嵁
    绛旓細select * from TableName
  • 鐢╝sp鎬庝箞璇诲嚭access涓涓瓧娈电殑璁板綍鐨勬绘暟???鎬``
    绛旓細select count(瀛楁鍚) from table
  • 濡備綍浣跨敤ASP闅忔満璇诲彇access鏁版嵁搴撲腑鐨勪竴鏉′俊鎭
    绛旓細rnd鏄asp鐨勪竴涓殢鍗冲嚱鏁帮紝浣嗘槸sql涓苟鏃犳鍑芥暟锛屾晠锛屼綘鐨勮繖涓猻ql璇彞鏄湁闂鐨勩備綘鍙互杩欐牱鍐 <!-- #include file="conn.asp" --> < set rs=server.CreateObject("adodb.recordset")rs.open "select top 1 id from url order by id desc",conn,1,1 if not rs.bof and not rs.eof ...
  • 鎬庝箞鍦ASP浠g爜閲岄潰瀹炵幇,鑾峰彇ACCESS鏁版嵁搴撲竴涓〃鐨勬渶鍚庝竴鏉¤褰曠殑鏁版嵁...
    绛旓細鏂规硶涓:rs.open sql,conn,1,1 rs.moveLast response.write(rs("瀛楁鍚"))rs.close set rs=nothing 瑙i噴:rs.moveLast鐨勪綔鐢ㄦ槸璁╂寚閽堢洿鎺ョЩ鍒版渶鍚庝竴鏉¤褰 鏂规硶浜:rs.open sql,conn,1,1 while not rs.EOF rs.MoveNext Wend response.write(rs("瀛楁鍚"))rs.close set rs=nothing 瑙i噴:rs...
  • 扩展阅读:免费网站在线观看人数在哪 ... 95网站csgo ... access视频 ... access怎么安装免费 ... 永久免费access进销存软件 ... access超出系统资源 ... access入口 ... access资源下载 ... asp连接access增删改 ...

    本站交流只代表网友个人观点,与本站立场无关
    欢迎反馈与建议,请联系电邮
    2024© 车视网