使用组件封装数据库操作(二)
前段日子发表的文章,数据库的连接代码可以直接在asp文件中显示出来。这次又进行了一次封装。
打开vb,新建activex控件,工程名称为webdb,类模块名称为getinfomation
引用”microsoft activex data object 2.6 library ”
private conn as adodb.connection
private rs as adodb.recordset
‘作用:判断数据库是否正确连结
'自己可以更改连接串
public function getconn()
conn.open "provider=sqloledb.1;persist security info=false;user id=sa;initial catalog=northwind;data source=yang"
if err.number <> 0 then
getconn = false
else
getconn = true
end if
end function
‘根据输入的雇员id,得到雇员的名称
public function getemployeename(stremployeeid as integer) as string
dim strsql as string
set rs = new adodb.recordset
strsql = "select lastname+firstname from employees where employeeid=" & stremployeeid
rs.open strsql, conn, adopenstatic, adlockoptimistic