출처: http://www.adopenstatic.com/faq/recordcounterror.asp
RecordCount returns -1
The use of the ADO Recordset's .RecordCount property requires either the use of:
- Static or Keyset server-side cursors or
- A client-side cursor (which returns a Static cursor)
(Note: some OLEDB Providers will return the correct recordcount with an adOpenDynamic cursor, others will not).
By default Recordsets are opened server-side, and with an adOpenForwardOnly cursor. Attempting to access the .RecordCount property with this type of cursor will return -1.
The easiest way to fix this is to change the cursor type to adOpenStatic. Doing this requires you to explicitly create a recordset object:
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open strSQL, objConn, adOpenStatic, adLockReadOnly, adCmdText
Attempting to implicitly create a recordset, eg like this:
Set objRS = objConn.execute(strSQL)
will not work, as the implicitly created recordset will have a default adOpenForwardOnly cursor.
As mentioned above, the alternative method is to use a client-side cursor. The client referred in this case is the OLEDB Cursor Service.
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.CursorLocation = adUseClient
objRS.Open strSQL, objConn,,adLockReadOnly, adCmdText
In order to be able to use server-side cursors and .Recordcount, the Recordset object must support either Approximate Positioning or Bookmarking. There has been discussion on the ActiveServerPages list to the effect that the MS Oracle OLEDB Provider (or earlier versions of this provider) do not support either Approximate Positioning or Bookmarking, hence require client-side cursors in order for .RecordCount to work.
'MFC' 카테고리의 다른 글
[MFC] 프로그램 중복실행 방지 (0) | 2014.12.04 |
---|---|
[MFC] 다양한 문자열 형식간 변환 (0) | 2014.07.29 |
[MFC] CListctrl, CTreectrl Drag And Drop 오류 (No Text Error) (0) | 2014.06.13 |
[MFC]기존 프로젝트에 WinSock(CSocket) 추가하기 (1) | 2014.05.21 |
[MFC] DLL 만들기 Sample Code (0) | 2014.02.04 |