Username: Password:

COM组件中怎样连接数据库-ASP教程,组件研发
来源:作者: 发布时间:2007-12-26 02:13:56

/* written by jaron ,2003-05-10 */
/* 原出处:江都资讯网 http://www.jiangdu.net */
/* 转载请注明出处和保留此版权信息 */
/* 欢迎使用sitemanager网站管理系统 http://sitemanager.cnzone.net */

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

喜欢本文,那就收藏到:

    Del.icio.us Google书签 Digg Live Bookmark Technorati Furl Yahoo书签 Facebook 百度搜藏 新浪ViVi 365Key网摘 天极网摘 和讯网摘 博拉网 POCO网摘 添加到饭否 QQ书签 Digbuzz我挖网
相关评论  我也要评论
还没有关于此文章的相关评论!
  • 昵称: (为空则显示guest)
  • 评论分数: ★ ★ ★★★ ★★★★ ★★★★★
  • 评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
  • 导航
    赞助商
    文章类别
    订阅