中国开发网: 论坛: 程序员情感CBD: 贴子 391882
haitao
整理了一个。。。。好像有点问题,也许少复制了什么。。。
<%

'On Error Resume Next
Set asplogobj = Server.CreateObject("AspLog.CoTAspLog")

sub asplog(s)
asplogobj.log s,1
end sub





Class c_db

Private SQLCommand
Private rsData
Dim Conn
Dim strConn


Private Sub Class_Initialize ' 设置 Initialize 事件。

strConn="Provider=SQLOLEDB ; Data Source=127.0.0.1 ; Initial Catalog=mis ; User ID=misuser ; Password=password"
Set Conn=Server.CreateObject("ADODB.Connection")
Conn.ConnectionString=strConn
Conn.Open
asplog "Class_Initialize"
Set rsData=Server.CreateObject("ADODB.Recordset")
sqlWhere=""
End Sub


Private Sub OpenSql

'response.Write("SQL=["+CStr(sqlCommand)+"]")
asplog "SQL=["+CStr(sqlCommand)+"]"

rsData. Open SQLCommand, conn, 1, 1

end sub

public function isEmpty()
if (rsData.Eof and rsData.Bof) then
isEmpty=true
else
isEmpty=false
end if
end function

Public Function testsql(aid)
SQLCommand="declare @tbinfo table (fid int ,fdata int)"
SQLCommand=SQLCommand & " insert @tbinfo values (1,1111)"
SQLCommand=SQLCommand & " insert @tbinfo values (2,2222)"
SQLCommand=SQLCommand & " insert @tbinfo values (3,3333)"
SQLCommand=SQLCommand & " insert @tbinfo values (4,4444)"
SQLCommand=SQLCommand & " insert @tbinfo values (5,5555)"

SQLCommand=SQLCommand & " declare @cid int "
SQLCommand=SQLCommand & " set @cid=" & Cstr(aid)
'--@cid==1,5 bad; 2,3,4 ok

SQLCommand=SQLCommand & " select a.*,isnull(b.fprevid,-1) fprevid,isnull(c.fnextid,-2) fnextid "
SQLCommand=SQLCommand & " from (SELECT * FROM @tbInfo where fID=@cid ) a "
SQLCommand=SQLCommand & " left join (select top 1 @cid as fid,fid as fprevid from @tbinfo where fid<@cid order by fprevid desc) b on a.fid=b.fid "
SQLCommand=SQLCommand & " left join (select top 1 @cid as fid,fid as fnextid from @tbinfo where fid>@cid order by fnextid) c on a.fid=c.fid "

'注释下面行,就是执行复杂的sql,不注释,就是执行简单的sql
SQLCommand="select "&Cstr(aid)&" as fd"

OpenSQL
asplog "recordcount="&Cstr(rsData.recordcount)

if isempty() then
asplog "test=empty!"
testsql=0
else
asplog "test=not empty!"
testsql=1
end if
'rsData.close
end function


Private Sub Class_Terminate ' 设置 Terminate 事件。
' conn.close
asplog "Class_Terminate"
End Sub

End Class




asplog "[[[" '这个输出了
Set db=new c_db '这个类的初始化log输出了
asplog "22222" '这个输出了
t=c_db.testsql(1)
asplog "testsql ret="&cstr(t) '这个没有输出!
asplog "]]]" '这个没有输出!
'然后就是这个类的终止的log输出

response.Write("TestSQL")


%>
我的blog:http://szhaitao.blog.hexun.com & http://www.hoolee.com/user/haitao
--以上均为泛泛之谈--
不尽牛人滚滚来,无边硬伤纷纷现 人在江湖(出来的),哪能不挨刀(总归是要的)
网络对话,歧义纷生;你以为明白了对方的话,其实呢?

您所在的IP暂时不能使用低版本的QQ,请到:http://im.qq.com/下载安装最新版的QQ,感谢您对QQ的支持和使用

相关信息:


欢迎光临本社区,您还没有登录,不能发贴子。请在 这里登录