VB使用ADO操作Access数据库

  Private Sub Form_Click()

  Dim db As New ADODB.Connection, RS As New ADODB.Recordset 'ADO连接对象和记录集

  Dim strSQL As String 'SQL字符串

  db.ConnectionString = "provider=Microsoft.Jet.OLEDB.4.0;Data source =" & App.Path & "/xs.mdb" '数据库连接

  db.Open '打开数据库

  strSQL = "select * from xj" 'SQL字符串

  RS.Open strSQL, db, 3, 1 '查询数据表

  Do While Not RS.EOF '循环输出查询到的结果

  Print RS!姓名; RS!性别; RS!班级; RS!出生年月 '在窗口中打印输出结果

  RS.MoveNext '记录下移

  Loop

  RS.Close '关闭记录集

  Set RS = Nothing

  End Sub