VB 数据库常用
\'-------------链接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