VB6.0使用ADO物件連線資料庫: (轉)

worldblog發表於2007-12-07
VB6.0使用ADO物件連線資料庫: (轉)[@more@] 

1. 定義連線:namespace prefix = o ns = "urn:schemas--com::office" />

Global connect 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.Provr = "Microsoft.jet.OLEDB.4.0"  // Access 97為3.51

DBconnect.ConnectionString = "FilePathFileName.mdb"

連線

DBconnect.Provider = "MSADORA"

DBconnect.ConnectionString = "user/mypass@servicename

連線 SERVER

DBconnect.Provider = "SQLOLEDB.1"

DBconnect.ConnectionString = "DATABASE= ;SERVER= ;UID= ;PWD= ;"

或者可以使用 DBconnect.Open "SERVER" , "USERID" , "PASS"

 

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/10752043/viewspace-989641/,如需轉載,請註明出處,否則將追究法律責任。

相關文章