《ASP》课程设计教案(12)
象可以执行查询外,另外,利用Connection对象的Execute方法和RecordSet对象的Open方法;返回一个记录集;
5、ADO连接对象(Connection)
? 连接对象在使用前必须创建该对象的实例,其创建方法为:
如:<% set conn=server.createobject(“adodb.connection”)%>
set rs=conn.execute(fhsql) //执行命令,产生记录集对象
? 利用记录集对象所提供的方法可以移动记录指针,以改变当前记录,记录是由若
干个字段构成的,所有字段的集合,构成字段集Fields,通过对字段的访问获得字段的当前值
相关属性:EOF BOF RecordCount AbslutePosition
相关方法:Movefirst movelast moveprevious movenext fields对象的属性:value name type size count rs.fields(字段名|字段顺序号).value
(chapter08/section123/ data_show.asp) <%
dsnpath=server.MapPath(\ //将虚拟路径转换为绝对路径 set conn=server.CreateObject(\ //创建对象 conn.open \fhsql=\学生表\
set rs=conn.execute(fhsql) //执行命令,产生记录集对象 for num=0 to rs.fields.count-1
response.write rs.fields(num).name next
response.write \do while not rs.eof
for num=0 to rs.fields.count-1 response.write rs(num) next
rs.movenext loop
rs.close //关闭对象 conn.close
set conn=nothing %>
