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

VB6.0使用ADO对象连接数据库: (转)[@more@] 

1. 定义连接对象XML:namespace prefix = o ns = "urn:schemas-microsoft-com:Office:office" />

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

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


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10748419/viewspace-980641/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/10748419/viewspace-980641/

你可能感兴趣的:(VB6.0使用ADO对象连接数据库: (转))