ADO CursorType Property
CursorType property는 Recordset object를 열 때 사용하기 위한 cursor type을 설정 또
는 반환한다. 이 property는 CursorTypeEnum 값을 취할 수 있다. Default는
adOpenForwardOnly이다.
Note : CursorLocation property 가 to adUseClient로 설정되었다면, CursorType
property 에 대한 유효한 settring은 오직 adOpenStatic이다.
Note : 지원되지 않은 값을 설정한다면 provider가 지원되는 CursorType으로 변경하기 때
문에 에러가 발생하지 않을 것이다.
Syntax
objRecordset.CursorType
예
% set conn=Server.CreateObject("ADODB.Connection") conn.Provider="Microsoft.Jet.OLEDB.4.0" conn.Open(Server.Mappath("northwind.mdb")) set rs = Server.CreateObject("ADODB.recordset") sql="SELECT * FROM Customers" rs.CursorLocation = adUseClient rs.CursorType = adOpenStatic rs.LockType = adLockBatchOptimistic rs.Open sql, conn %>
CursorTypeEnum Values
검색 루티 만들기
search.asp
데이터베이스에 연결하기 위해 데이터베이스 연결 설정 파일인 dbcon.asp 파일을 include 한다.
<!--#include file=dbcon.asp -->
Request 객체를 사용하여 id, name, sex, keyfield , key 값을 불러온다.
id=request("id") name=request("name") sex=request("sex") keyfield=request("keyfield") key=request("key")
select 구문을 사용하여 알아온 레코드의 개수를 totalcount 라는 변수에 저장한다. key 값이 없다면 전체 레코드의 개수를 알아온다.
키 값(검색어) 이 있다면 키 값에 따라 검색된 레코드의 개수를 totalcount 변수에 저장한다.
if key ="" then sql ="SELECT count(*) as totalcount FROM usert" else sql="select count(*) as totalcount from usert where " & keyfield & " like '%" & key & "%'" end if
sql 질의문을 실행한다.
Set rs=db.Execute(sql)
검색 자료 출력
연결 객체를 생성한다.
Set DbRec=Server.CreateObject("ADODB.Recordset")
DbRec.CursorType=1
검색어에 따른 레코드를 가져온다. 만약 키 값(검색어) 이 없다면 데이터베이스의 usert 테이블에서 모든 데이터를 가져온다.
if key="" Then
DbRec.Open "Select * From usert ORDER by id asc ", db
else
키 값이 있다면 키 값(검색어)을 조건으로 하여 데이터베이스의 usert 테이블에서 레코드를 가져온다. 예를 들어
키 필드 값(이름) 을 "이름 " 을 선택하고, 키 값(검색어)을 입력하고, 검색 버튼을 클릭하게 되면 검색어 데이터를 가져와서
목록보기에 출력한다.
else
DbRec.Open " Select * From usert where " & keyfield & " like '%" & key & "%' Order by id asc ", db
end if
검색된 레코드의 개수만큼 반복하여 데이커 값을 출력한다.
<% For i =1 to rs("totalcount") %> <tr> <td><%= DbRec("id")%></td> <td><%= DbRec("name") %></td> <td><%= DbRec("sex") %></td> <td><%= DbRec("memo") %></td> </tr> <% DbRec.movenext Next %>
search.asp
<!--#include file=./include/header.asp --> <script> function add(){ location.href="inputform.asp" ; } </script> </head> <body> <!--#include file=dbcon.asp --> <% id=request("id") name=request("name") sex=request("sex") keyfield=request("keyfield") key=request("key") if key ="" then sql ="SELECT count(*) as totalcount FROM usert" else sql="select count(*) as totalcount from usert where " & keyfield & " like '%" & key & "%'" end if Set rs=db.Execute(sql) %> <p> </p> <div class="rows" > <div class="col-xs-12 col-sm-12" > <h3 class="text-center">목록 보기</h3> <p> </p> <div class="col-xs-3 col-som-3"></div> <div class="col-xs-6 col-som-6"> <div class="text-center"> <p> <button onclick="add()" class="btn-primary">추가하기</button> </p> <p class="text-left"> 레코드 총 수 : 총 <%= rs("totalcount") %>개<br/> </p> <form class="form" action="search.asp" method="post"> <div class="col-sm-2"> <select name="keyfield" class="form-control"> <option value="name">이름</option> <option value="sex">성별</option> </select> </div> <div class="col-sm-2"> <input type="text" name="key" class="form-control" /> </div> <div class="col-sm-2"> <input type="submit" value="Search" name="submit" class="form-control btn-success"/> </div> </form> <p><br /> </p> <table class="table"> <tr> <th>번호</th> <th>이름</th> <th>성별</th> <th>메모</th> </tr> <% Set DbRec=Server.CreateObject("ADODB.Recordset") DbRec.CursorType=1 if key="" Then DbRec.Open "Select * From usert ORDER by id asc ", db else DbRec.Open " Select * From usert where " & keyfield & " like '%" & key & "%' Order by id asc ", db end if %> <% For i =1 to rs("totalcount") %> <tr> <td><%= DbRec("id")%></td> <td><%= DbRec("name") %></td> <td><%= DbRec("sex") %></td> <td><%= DbRec("memo") %></td> </tr> <% DbRec.movenext Next %> </table> </div> </div> </div> </div> </body> </html>
댓글 ( 4)
댓글 남기기