第一范文网 - 专业文章范例文档资料分享平台

VB连接数据库的方法2

来源:用户分享 时间:2025/10/1 14:19:08 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

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;

搜索更多关于: VB连接数据库的方法2 的文档
VB连接数据库的方法2.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c1l8ix44i168wrp7237vu_4.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top