VERSION 5.00
Object = "{CDE57A40-8B86-11D0-B3C6-00A0C90AEA82}#1.0#0"; "MSDATGRD.OCX"
Begin VB.Form Form4 
   Caption         =   "代码建立连接对象"
   ClientHeight    =   2910
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   4680
   LinkTopic       =   "Form4"
   ScaleHeight     =   2910
   ScaleWidth      =   4680
   StartUpPosition =   3  '窗口缺省
   Begin VB.CommandButton Command1 
      Caption         =   "ADO数据控件"
      Height          =   395
      Left            =   60
      TabIndex        =   3
      Top             =   2520
      Width           =   1455
   End
   Begin VB.CommandButton Command2 
      Caption         =   "数据环境设计器"
      Height          =   395
      Left            =   1620
      TabIndex        =   1
      Top             =   2520
      Width           =   1455
   End
   Begin VB.CommandButton Command3 
      Caption         =   "代码配合ADO"
      Height          =   395
      Left            =   3180
      TabIndex        =   0
      Top             =   2520
      Width           =   1395
   End
   Begin MSDataGridLib.DataGrid DataGrid1 
      Bindings        =   "sy11-19d.frx":0000
      Height          =   2415
      Left            =   0
      TabIndex        =   2
      Top             =   60
      Width           =   4635
      _ExtentX        =   8176
      _ExtentY        =   4260
      _Version        =   393216
      HeadLines       =   1
      RowHeight       =   15
      BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "宋体"
         Size            =   9
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "宋体"
         Size            =   9
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ColumnCount     =   2
      BeginProperty Column00 
         DataField       =   ""
         Caption         =   ""
         BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
            Type            =   0
            Format          =   ""
            HaveTrueFalseNull=   0
            FirstDayOfWeek  =   0
            FirstWeekOfYear =   0
            LCID            =   2052
            SubFormatType   =   0
         EndProperty
      EndProperty
      BeginProperty Column01 
         DataField       =   ""
         Caption         =   ""
         BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
            Type            =   0
            Format          =   ""
            HaveTrueFalseNull=   0
            FirstDayOfWeek  =   0
            FirstWeekOfYear =   0
            LCID            =   2052
            SubFormatType   =   0
         EndProperty
      EndProperty
      SplitCount      =   1
      BeginProperty Split0 
         BeginProperty Column00 
         EndProperty
         BeginProperty Column01 
         EndProperty
      EndProperty
   End
End
Attribute VB_Name = "Form4"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
    Form1.Show
End Sub

Private Sub Command2_Click()
    Form2.Show
End Sub

Private Sub Command3_Click()
    Form3.Show
End Sub

Private Sub Form_Load()
    Dim mlink As String, msql As String
    ' 在DAO中是定义Database对象，在ADO中应定义Connection连接对象
    Dim db As Connection
    Dim rs As Recordset                         ' 定义Recordset类型变量
    Set db = New Connection                     ' 设置新的Connection对象db
    db.CursorLocation = adUseClient             ' 设置db为客户端
    Set rs = New Recordset                      ' 设置新的Recordset对象
    ' 通过连接字符串mlink指定连接的数据库，使用Open方法打开数据库
    mlink = "Provider=Microsoft.Jet.OLEDB.3.51; Data Source=Mydb.mdb;"
    db.Open mlink                               ' 打开数据库
    ' 使用SQL确定记录集，用Open方法打开记录集，保存在记录集对象rs
    msql = "Select 姓名,学号,性别,出生年月,专业,家庭地址 From Student"
    rs.Open msql, db, adOpenStatic, adLockOptimistic
    Set DataGrid1.DataSource = rs               ' 将DataGrid1绑定到rs
End Sub

