当前位置: 移动技术网 > IT编程>开发语言>Asp > asp中COM组件中如何连接数据库的代码

asp中COM组件中如何连接数据库的代码

2017年12月12日  | 移动技术网IT编程  | 我要评论
vb- 工程 -引用 - ado 2.0 ,建一个类db,工程名设为 sqlconn
以下是偶程序中的部分代码,大家有空可以试试
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

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网