Home Database Mysql Tutorial ADO参考, 各种连接数据库字符串

ADO参考, 各种连接数据库字符串

Jun 07, 2016 pm 03:48 PM
Jelly string database connect

ADO参考 摘要:在OLE DB(建立于低层ODBC 之上,是一个针对 SQL 数据源和非SQL 数据源,如邮件和目录等进行操作的应 用程序接口)的基础上,Microsoft 推出了另一个数据访问对象模型:ADO(ActiveX Da ta Object:ActiveX数据对 象)。ADO 采用基于 DAO 和 RDO

ADO参考      
摘要:在OLE DB(建立于低层ODBC 之上,是一个针对 SQL 数据源和非SQL 数据源,如邮件和目录等进行操作的应用程序接口)的基础上,Microsoft 推出了另一个数据访问对象模型:ADO(ActiveX Data Object:ActiveX数据对象)。ADO 采用基于 DAO 和 RDO 的对象,并提供比 DAO 和 RDO 更简单的对象模型,它包含一些简化对数据存储区数据的访问任务的内置对象。同时ADO具有强大的功能和灵活性,它可以使用相同的编程模式连接到不同的数据库,为我们提供了数据库访问接口。
ADO对象 
ADO 模型中定义了六个常用的对象:Connection、Command、Recordset、Error、Field和Parameter对象,通过这些对象的属性和方法,我们可以很方便地建立数据库连接,执行SQL查询以及存取操作。下图直观地描述了对象之间的关系:

ADO参考, 各种连接数据库字符串

Connection对象
代表打开的、与数据源的连接。一般使用 Connection 对象的集合、方法、和属性执行下列操作: 
1、在打开连接前使用 ConnectionString、ConnectionTimeout 和 Mode 属性对连接进行配置。
2、使用 DefaultDatabase 属性设置连接的默认数据库。
3、使用 Provider 属性指定 OLE DB 提供者。
4、使用 Open 方法建立到数据源的物理连接。使用 Close 方法将其断开。
5、使用 Execute 方法执行对连接的命令,并使用 CommandTimeout 属性对执行进行配置。
6、使用 BeginTrans、CommitTrans 和 RollbackTrans 方法以及 Attributes 属性管理打开的连接上的事务(如果提供者支持则包括嵌套的事务)。
 
7、使用 Errors 集合检查数据源返回的错误。   
Command对象
定义了对数据源执行的命令,我们可以使用 Command 对象的集合、方法、属性进行下列操作:      
1、使用 CommandText 属性定义命令(例如,SQL 语句)的可执行文本。
2、通过 Parameter 对象和 Parameters 集合定义参数化查询或存储过程参数。
3、使用 Execute 方法执行命令并在适当的时候返回 Recordset 对象。 
4、执行前使用 CommandType 属性指定命令类型以优化性能。
5、使用 CommandTimeout 属性设置等待命令执行的秒数。
6、通过设置 ActiveConnection 属性关联打开的连接。
7、设置 Name 属性将 Command 标识为与 Connection 对象关联的方法。
8、将 Command 对象传送给 Recordset 的 Source 属性以便获取数据。
ADO连接EXCEL2003表

1

2

Conn.Open "provider=microsoft.jet.oledb.4.0;extended properties=excel 8.0;data source=" & 文件全路

Cnn.Open "provider=microsoft.jet.oledb.4.0;Extended properties='excel 8.0;hdr=no';data source=" & 路径设置

Copy after login

“HDR=NO"应该表示所选区域首行不做为标题,如果不设置该项,系统默认将首行非空记录做为ADO记录集的标题行

ADO连接txt文件

1

2

3

4

5

6

7

8

9

10

11

ActiveSheet.Cells.Clear

myText = "学生成绩.txt"

myPath = ThisWorkbook.Path

CnnStr = "Driver={Microsoft Text Driver (*.txt; *.csv)};" & "DBQ=" & myPath '

Cnn.Open CnnStr

rs.Open myText, cnn, adopenkeset, adLockOptimistic

ADO连接ACCESS2003的数据库

strAccess = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + _ThisWorkbook.Path + "\data\数据库档案.MDB" + _";Jet OLEDB:Database Password=" & "123"

'定义连接字符串 数据源 密码(最长20个字符)

Set ADOcn = New ADODB.Connection     ' 赋值变量为对象引用

ADOcn.Open strAccess     '打开连接

Copy after login


ADO连接FOXPRO 6.0的数据库

1

2

3

4

5

6

7

8

9

10

set conn =createobject("adodb.connection")

set rs=createobject("adodb.recordset")

sql="select * from aa.dbf"

conn.open "driver={microsoft visual foxpro driver };sourcetype=dbf;excelusive=no;sourcedb=" & 文件路径

rs.open sql ,conn

msgbox rs.recordcount

rs.close

conn.close

conn=nothing

rs=nothing

Copy after login
需要安装foxpro 的odbc驱动
ADO连接SQL SERVER的数据库

1

2

3

4

5

6

7

8

9

10

11

Dim cnn1 As ADODB.Connection

Dim strCnn As String

   ' 打开连接。

strCnn = "Provider=sqloledb;" & _

   "Data Source=srv;Initial Catalog=pubs;User Id=sa;Password=; "

cnn1.Open strCnn

ADO连接ACCESS2007的数据库

con.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Access2007数据源 & _

         ";Jet OLEDB:Database Password=" & 密码

con.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Excel2007数据源 & _

         ";Jet OLEDB:Database Password=" & 密码

Copy after login


ADO连接oracle数据库

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

Sub connect_数据库()

Dim strconnt As String

Set connt = New ADODB.Connection

Dim rs As Object

Set rs = New ADODB.Recordset

Dim sevip, Db, user, pwd As String

'设服务器地址、所连数据,及登录用户密码

sevip = "****"

Db = "****"

user = "****"

pwd = "****"

strconnt = "DRIVER={Microsoft ODBC for Oracle};Password=apps;User ID=apps;Data Source=demo" '

connt.ConnectionString = strconnt

connt.Open

End Sub

Copy after login


ADO连接mysql数据库

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

Sub connect_数据库()

  Dim strconnt As String

  strconnt = ""

  Set connt = New ADODB.Connection

  Dim rs As Object

  Set rs = New ADODB.Recordset

  Dim sevip, Db, user, pwd As String

  '设服务器地址、所连数据,及登录用户密码

  sevip = "192.168.*.*"

  Db = "***"

  user = "***"

  pwd = "****"

  strconnt = "DRIVER={MySql ODBC 3.51 Driver};SERVER=" & sevip & ";Database=" & Db & ";Uid=" & user & ";Pwd=" & pwd & ";Stmt=set names GBK" '

  connt.ConnectionString = strconnt

  connt.Open

End Sub

Copy after login


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How does Go language implement the addition, deletion, modification and query operations of the database? How does Go language implement the addition, deletion, modification and query operations of the database? Mar 27, 2024 pm 09:39 PM

How does Go language implement the addition, deletion, modification and query operations of the database?

How to repeat a string in python_python repeating string tutorial How to repeat a string in python_python repeating string tutorial Apr 02, 2024 pm 03:58 PM

How to repeat a string in python_python repeating string tutorial

Detailed tutorial on establishing a database connection using MySQLi in PHP Detailed tutorial on establishing a database connection using MySQLi in PHP Jun 04, 2024 pm 01:42 PM

Detailed tutorial on establishing a database connection using MySQLi in PHP

iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos Jul 18, 2024 am 05:48 AM

iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos

How does Hibernate implement polymorphic mapping? How does Hibernate implement polymorphic mapping? Apr 17, 2024 pm 12:09 PM

How does Hibernate implement polymorphic mapping?

An in-depth analysis of how HTML reads the database An in-depth analysis of how HTML reads the database Apr 09, 2024 pm 12:36 PM

An in-depth analysis of how HTML reads the database

How to convert string to float in PHP How to convert string to float in PHP Mar 27, 2024 pm 12:48 PM

How to convert string to float in PHP

PHP String Operation: Remove Extra Commas and Keep Only Commas Implementation Tips PHP String Operation: Remove Extra Commas and Keep Only Commas Implementation Tips Mar 28, 2024 pm 03:02 PM

PHP String Operation: Remove Extra Commas and Keep Only Commas Implementation Tips

See all articles