以下是偶程序中的部分代码,大家有空可以试试
option explicit
public strerror as string
public conn as new adodb.connection
public rs as new adodb.recordset
public property get errorstring() as string
errorstring = strerror
end property
public function conn_open(strsqlservername, strsqldbusername, strsqldbpassword, strsqldbname)
dim strcon as string
set conn = new adodb.connection
on error goto errhandler:
strcon = "provider=sqloledb;server=" & strsqlservername & ";user id=" & strsqldbusername & ";password=" & strsqldbpassword & ";database=" & strsqldbname & ";"
conn.open strcon
errhandler:
strerror = "错误源:" & err.source & vbcrlf & "描述:" & err.description
exit function
end function
function getrootid(byval classid)
dim query
query = "select class_id,rootid from tblcategory where class_id='" & classid & "'"
set rs = conn.execute(query)
if not (rs.eof and rs.bof) then
getrootid = rs("rootid")
else
getrootid = classid
end if
rs.close
set rs = nothing
end function
编译后,在asp中这样用
function getrootid(byval id) ' 获取根类id号
set s_db = server.createobject( "sqlconn.db")
s_db.conn_open strsqlservername,strsqldbusername,strsqldbpassword,strsqldbname
getrootid = s_db.getrootid(id)
set s_db=nothing
end function