\'-------------链接MSSQL,建立数据集-------------------------
\'引入Microsoft ActiveX Data Objects 2.5 Library

Dim Conn As New ADODB.Connection
Dim theSource As New ADODB.Command
Dim theRS As New ADODB.Recordset

Conn.Open "Provider=SQLOLEDB.1;Password=sa;Persist Security Info=True;User ID=sa;Initial Catalog=Local;Data Source=(local)"

Set theSource.ActiveConnection = Conn
theSource.CommandText = "SELECT * from table"
theRS.CursorLocation = adUseClient
theRS.Open theSource, , adOpenStatic, adLockOptimistic

\'------------------链接Access数据库----------------------------
    \'这是Access数据库的

    Public rs As New ADODB.Recordset
    Public conn As New ADODB.Connection

    Dim dFile As String
    Dim sql As String
    
    dFile = App.Path & "\db.mdb"
    conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dFile
    conn.Open

    sql = "select * from [table]"
    rs.Open sql, conn, 1, 2

 

版权声明:本文为lichsky原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/lichsky/p/3308737.html