定义连接对象 Global DBconnect As New ADODB.Connection 2. 执行连接语句 If DBconnect.State = adStateOpen And Not IsEmpty(adStateOpen) Then" name="description" />

VB6.0使用ADO对象连接数据库:

发表于:2007-05-25来源:作者:点击数: 标签:数据库VB6.0连接ado对象
1. MI LY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">定义连接对象 Global DBconnect As New ADODB.Connection 2. 执行连接语句 If DBconnect.State = adStateOpen And Not IsEmpty(adStateOpen) Then
 

1. MILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">定义连接对象

Global DBconnect As New ADODB.Connection

2. 执行连接语句

If DBconnect.State = adStateOpen And Not IsEmpty(adStateOpen) Then DBconnect.Close

 

l         连接ODBC

    DBconnect.ConnectionString = "dsn=DataAliasName;uid=UserID;pwd=Passwd;"

l         直接连接Aclearcase/" target="_blank" >ccess

Dbconnect.Provider = "Microsoft.jet.OLEDB.4.0"  // Access 973.51

DBconnect.ConnectionString = "FilePath\FileName.mdb"

l         连接Oracle

DBconnect.Provider = "MSADORA"

DBconnect.ConnectionString = "user/mypass@servicename

l         连接SQL Server

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

原文转自:http://www.ltesting.net