Username: Password:

vb连接sql模块代码-数据库专栏,SQL Server
来源:作者: 发布时间:2007-12-25 13:42:26


public conn as new adodb.connection
public rs as new adodb.recordset
public addflag as boolean

public function opencn(byval cip as string) as boolean
dim mag as string
on error goto strerrmag
set conn = new adodb.connection
conn.connectiontimeout = 25
conn.provider = "sqloledb"
conn.properties("data source").value = cip    服务器的名字
conn.properties("initial catalog").value = "zqoa"           库名
conn.properties("integrated security").value = "sspi"   登陆类型
conn.properties("user id").value = "sa"
conn.properties("password").value = "sa"
conn.open
opencn = true
addflag = true
exit function
strerrmag:
    mag = "data cant connect"
    call msgbox(mag, vbokonly, "error:data connect")
    addflag = false
    exit function
end function


public sub clocn()
on error resume next
if conn.state <> adstateclosed then conn.close
set conn = nothing
end sub

public function openrs(byval strsql as string) as boolean   连接数据库记录集
dim mag as string
dim rpy as boolean
on error goto strerrmag
    set rs = new adodb.recordset
    if addflag = false then rpy = true
    with rs
    .activeconnection = conn
    .cursorlocation = aduseclient
    .cursortype = adopenkeyset
    .locktype = adlockoptimistic
    .open strsql
    end with
    addflag = true
    openrs = true
    end
    exit function
strerrmag:
    mag = "data not connect"
    call msgbox(mag, vbokonly, "error:connect")
    openrs = false
    end
    exit function
end function
public sub clors()
on error resume next
if rs.state <> adstateclosed then rs.clone
set rs = nothing
end sub


 

喜欢本文,那就收藏到:

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