加个好友 求教下VB连接SQL的方法吧 怎么连都出错
发布网友
发布时间:2024-01-04 03:57
我来回答
共1个回答
热心网友
时间:2024-07-31 06:44
第一种、直接连接方式
Global dbserver As Connection
Global adore1 As New ADODB.Recordset
Set dbserver = New Connection
dbserver.CursorLocation = adUseClient
dbserver.Open "provider=MSDASQL;DSN=ZCDB;UID=sa;PWD="
If adore1.State = adStateOpen Then adore1.Close
adore1.Open "select * from 系统设置", dbserver, adOpenKeyset, adLockOptimistic
user_name = adore1.Fields("用户名")
第二种、ODBC方式
Global dbdata As DAO.Database
Dim resystem As DAO.Recordset
Set dbdata = OpenDatabase("", True, True, "ODBC;DSN=ZCDB;UID=SA;PWD=")
Set resystem = dbdata.OpenRecordset("系统设置")
user_name = resystem.Fields("用户名")