AdoCnn.CursorLocation = adUseClient
'.open后面的字符串可以参考ADO控件连接.ConnectionString后面的的字符串
AdoCnn.Open\Info=False;Data Source=\Properties='Excel 8.0;HDR=Yes'\
AdoRs.Open \adLockPessimistic, adCmdText
Set DataGrid1.DataSource = AdoRs Set AdoRs = Nothing Set AdoCnn = Nothing End Sub
4.'ADO代码与Oracle数据库连接 Private Sub Command4_Click() Dim AdoCnn As ADODB.Connection Dim AdoRs As ADODB.Recordset Set AdoCnn = New ADODB.Connection Set AdoRs = New ADODB.Recordset AdoCnn.CursorLocation = adUseClient
'.open后面的字符串可以参考ADO控件连接.ConnectionString后面的的字符串
AdoCnn.Open \Security Info=True;User ID=chncmadb;Data Source=towebserver\AdoRs.Open \adLockPessimistic, adCmdText
Set DataGrid1.DataSource = AdoRs
Set AdoRs = Nothing Set AdoCnn = Nothing End Sub
5.'ADO代码与SQLserver数据库连接 '未测试
Private Sub Command5_Click() Dim AdoCnn As ADODB.Connection Dim AdoRs As ADODB.Recordset Set AdoCnn = New ADODB.Connection Set AdoRs = New ADODB.Recordset AdoCnn.CursorLocation = adUseClient
'.open后面的字符串可以参考ADO控件连接.ConnectionString后面的的字符串
AdoCnn.Open \Info=True;User ID=111;Initial Catalog=111;Data Source=111\AdoRs.Open \adLockPessimistic, adCmdText
Set DataGrid1.DataSource = AdoRs Set AdoRs = Nothing Set AdoCnn = Nothing End Sub
连库
Dim DLYHM, DLMM, DLSLM As String Dim Grecordset As New ADODB.Recordset
Dim Gconnection_HQ As New ADODB.Connection DLYHM = \用户名 DLMM = \登录密码
DLSLM = \中的实例名 LSsjk = DLYHM + \
LSsjk = \ Set Gconnection_HQ = New ADODB.Connection Gconnection_HQ.Open LSsjk
读数据
Set Grecordset = New ADODB.Recordset
Grecordset.Open \* from 表名 where 字段名='\& 字段值 & \Gconnection_HQ, adOpenStatic, adLockOptimistic ‘索引条件 变量 = Trim(Grecordset.Fields(\读取字段名\Grecordset.Close
最好建ODBC配置数据源,然后连接
linkcn = \数据源名;Persist Security Info=True;User ID=用户;Password=密码 \
找tnsnames.ora文件,我的在oracle\\product\\10.2.0\\db_1\\NETWORK\\ADMIN下。 记事本打开后
……(DESCRIPTION = (ADDRESS =
(PROTOCOL = TCP)
(HOST = 远程服务器名或者IP地址) (PORT = 1521) )
(CONNECT_DATA = (SERVER = DEDICATED)
(SERVICE_NAME = 服务器的数据库名) ) ……
手动改一下好了~~
Microsoft ODBC for Oracle Type: ODBC Driver Usage: Driver={Microsoft ODBC for Oracle} Manufacturer: Microsoft More info about this driver ? Customize string example values ? New version Driver={Microsoft ODBC for Oracle};Server=myServerAddress;Uid=myUsername;Pwd=myPassword; Microsoft ODBC Driver for Oracle Type: ODBC Driver Usage: Driver={Microsoft ODBC Driver for Oracle} Manufacturer: Microsoft More info about this driver ? Customize string example values ? Old version Driver={Microsoft ODBC Driver for Oracle};ConnectString=OracleServer.world;Uid=myUsername;Pwd=myPassword;
相关推荐: