vb与sql server 2000数据库连接的问题SOS SOS!

xax 2002-04-25 04:48:33
如何用VB的ADO与SQL SERVER 建立连接,谢谢!
...全文
7 点赞 收藏 4
写回复
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
LabAdmin 2002-04-25
建立ODBC连接DSN,如test

然后:

Dim Conn as new adodb.Connection
Dim Rs as new adodb.RecordSet
Conn.Open "DSN=test","sa",""

Set Rs = Conn.Excute("查询字符串")

if Not rs.eof() then
。。。
回复
wzsswz 2002-04-25
dim cnstr as string

cnstr = "Provider = SQLOLEDB.1;Password=" + youpasd + ";Persist Security Info=True;User ID=sa;Initial Catalog=" + youdb + ";Data Data Source=" + youserver + ";"
用 adodc1:
With adodc1
.connectionstring = cnstr
.username = "sa"
.Password = youpasd
.RecordSource = yousql
.Refresh
End With

或者用ADODB:
Dim cnn1 As ADODB.Connection
Dim rst1 As ADODB.Recordset
Set cnn1 = New ADODB.Connection
Call cnn1.Open(cnstr)
Set rst1 = New ADODB.Recordset
rst1.ActiveConnection = cnn1
On Error GoTo errorhandle
Call rst1.Open(yousql, cnn1, adOpenKeyset, adLockReadOnly)
。。。
以上这样,不知是否满意?。。。。。。。。。。。
回复
tony_jian 2002-04-25
同意楼上.
回复
heyijpn 2002-04-25
Public Cn As ADODB.Connection
Set Cn = New ADODB.Connection
Cn.ConnectionString = "Provider=SQLOLEDB.1;" & _
"Persist Security Info=False;" & _
"User ID=sa;" & _
"Password=;" & _
"Database=DataBaseName;" & _
"Server=YourServerName"
Cn.Open
回复
发动态
发帖子

1180

社区成员

VB 数据库(包含打印,安装,报表)
申请成为版主
社区公告
暂无公告