VB使用ADO对象链接数据库
1. 定义连接对象
Global DBconnect As New ADODB.Connection
2. 执行连接语句
If DBconnect.State = adStateOpen And Not IsEmpty(adStateOpen) Then DBconnect.Close
连接ODBC
DBconnect.ConnectionString = "dsn=DataAliasName;uid=UserID;pwd=Passwd;"
直接连接Access为
Dbconnect.Provider = "Microsoft.jet.OLEDB.4.0" // Access 97为3.51
DBconnect.ConnectionString = "FilePathFileName.mdb"
连接Oracle
DBconnect.Provider = "MSADORA"
DBconnect.ConnectionString = "user/mypass@servicename
DBconnect.Provider = "SQLOLEDB.1"
DBconnect.ConnectionString = "DATABASE= ;SERVER= ;UID= ;PWD= ;"
或者可以使用 DBconnect.Open "SERVER" , "USERID" , "PASSWORD"
DBConnect.Open
3. 取查询结果集
Global RS As New ADODB.Recordset
Global PS As New ADODB.Recordset
If RS.State = adStateOpen And Not IsEmpty(adStateOpen) Then RS.Close
RS.Open SQLStr, DBconnect, adOpenKeyset
4. 执行SQL语句
DBconn.Execute SQLStr
5. 关闭数据库
DBconnect.Close
作者:涵曦(www.hanxi.cc)
出处:hanxi.cnblogs.com
GitHub:github.com/hanxi
Email:im.hanxi@gmail.com
文章版权归本人所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
《 Skynet 游戏服务器开发实战》
-
学习地址:
-
优惠推荐码:
2CZ2UA5u
-
可以先免费试学前 2 章内容