怎样在程序中建立ODBC的连接? 在线等!急急!!
前面我已经看了类似的帖子(由mizuhata发的),并且按照大头河马的代码去连接SQL Server数据库。代码如下:
Dim sAttributes As String
nRet = SQLConfigDataSource(vbAPINull, ODBC_ADD_DSN, "SQL
Server", "DSN=JJJ") ’这一句是成功的。
sAttributes = "Server=jdycserver"
sAttributes = sAttributes & "DESCRIPTION="
sAttributes = sAttributes & "DSN=JJJ"
sAttributes = sAttributes & "DATABASE=xchk"
nRet = SQLConfigDataSource(vbAPINull, ODBC_CONFIG_DSN = 2, "SQL Server", sAttributes)‘这一句始终返回值为零。并且发现ODBC中JJJ的 Server=JJJ,DSN=JJJ,DESCRIPTION="",DATABASE=xchk.
Set cnn = New ADODB.Connection
cnn.ConnectionString = "DSN=JJJ"
cnn.Open
Set rst = New ADODB.Recordset
rst.Open "select * from StudInfo", cnn, adOpenDynamic, adLockOptimistic, -1
请高手指教。
前面我已经看了类似的帖子(由mizuhata发的),并且按照大头河马的代码去连接SQL Server数据库。代码如下:
Dim sAttributes As String
nRet = SQLConfigDataSource(vbAPINull, ODBC_ADD_DSN, "SQL
Server", "DSN=JJJ") ’这一句是成功的。
sAttributes = "Server=jdycserver"
sAttributes = sAttributes & "DESCRIPTION="
sAttributes = sAttributes & "DSN=JJJ"
sAttributes = sAttributes & "DATABASE=xchk"
nRet = SQLConfigDataSource(vbAPINull, ODBC_CONFIG_DSN = 2, "SQL Server", sAttributes)‘这一句始终返回值为零。并且发现ODBC中JJJ的 Server=JJJ,DSN=JJJ,DESCRIPTION="",DATABASE=xchk.
Set cnn = New ADODB.Connection
cnn.ConnectionString = "DSN=JJJ"
cnn.Open
Set rst = New ADODB.Recordset
rst.Open "select * from StudInfo", cnn, adOpenDynamic, adLockOptimistic, -1
请高手指教。
Set rstCmms = New ADODB.Recordset
With rstCmms
.CursorType = adOpenDynamic
.CursorLocation = adUseClient
.LockType = adLockOptimistic
.Source = "select * from tblaccount "
Set .ActiveConnection = cnn
.Open
End With
Set adodc1.Recordset = rstCmms---------
'----------------
cn.ConnectionString = "provider=SQLOLEDB;server=www;uid=sa;pwd="
cn.CursorLocation = adUseClient
cn.Open
Dim rs As ADODB.Recordset
---------------------------------------------------Set con = New ADODB.Connection
cnn1.Open "provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=Bookstore;Data Source=192.168.0.250;"'Bookstore 为数据库名Set rs = New ADODB.Recordset
rs.Open "StudInfo", con, adOpenDynamic, adLockOptimistic'StudInfo 为数据表名