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表

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文件

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的数据库

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的数据库
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数据库

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数据库

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 AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

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 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

1. First open pycharm and enter the pycharm homepage. 2. Then create a new python script, right-click - click new - click pythonfile. 3. Enter a string, code: s="-". 4. Then you need to repeat the symbols in the string 20 times, code: s1=s*20. 5. Enter the print output code, code: print(s1). 6. Finally run the script and you will see our return value at the bottom: - repeated 20 times.

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

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

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

Hibernate polymorphic mapping can map inherited classes to the database and provides the following mapping types: joined-subclass: Create a separate table for the subclass, including all columns of the parent class. table-per-class: Create a separate table for subclasses, containing only subclass-specific columns. union-subclass: similar to joined-subclass, but the parent class table unions all subclass columns.

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

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

How to handle database connection errors in PHP How to handle database connection errors in PHP Jun 05, 2024 pm 02:16 PM

To handle database connection errors in PHP, you can use the following steps: Use mysqli_connect_errno() to obtain the error code. Use mysqli_connect_error() to get the error message. By capturing and logging these error messages, database connection issues can be easily identified and resolved, ensuring the smooth running of your application.

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

HTML cannot read the database directly, but it can be achieved through JavaScript and AJAX. The steps include establishing a database connection, sending a query, processing the response, and updating the page. This article provides a practical example of using JavaScript, AJAX and PHP to read data from a MySQL database, showing how to dynamically display query results in an HTML page. This example uses XMLHttpRequest to establish a database connection, send a query and process the response, thereby filling data into page elements and realizing the function of HTML reading the database.

How to connect to remote database using Golang? How to connect to remote database using Golang? Jun 01, 2024 pm 08:31 PM

Through the Go standard library database/sql package, you can connect to remote databases such as MySQL, PostgreSQL or SQLite: create a connection string containing database connection information. Use the sql.Open() function to open a database connection. Perform database operations such as SQL queries and insert operations. Use defer to close the database connection to release resources.

How to use database callback functions in Golang? How to use database callback functions in Golang? Jun 03, 2024 pm 02:20 PM

Using the database callback function in Golang can achieve: executing custom code after the specified database operation is completed. Add custom behavior through separate functions without writing additional code. Callback functions are available for insert, update, delete, and query operations. You must use the sql.Exec, sql.QueryRow, or sql.Query function to use the callback function.

See all articles