form1.frm

来自「vb数据库编程资料」· FRM 代码 · 共 40 行

FRM
40
字号
VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   1125
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   5250
   LinkTopic       =   "Form1"
   ScaleHeight     =   1125
   ScaleWidth      =   5250
   StartUpPosition =   3  '窗口缺省
   Begin VB.CommandButton Command2 
      Caption         =   "建立到教学数据库的连接"
      Height          =   495
      Left            =   1080
      TabIndex        =   0
      Top             =   120
      Width           =   2295
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim CnB As New ADODB.Connection
Dim Sqlstr As String
Private Sub Command2_Click()
 Dim Cnbstring As String
 Cnbstring = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & App.Path & "\教学.mdb"
 With CnB
     .ConnectionString = Cnbstring
     .ConnectionTimeout = 10
     .Open '给连接的ConnectionString属性赋值,然后使用求带参数的Open方法打开连接
  End With
  MsgBox ("连接成功")
  Sqlstr = "Insert into 学生表(学号,姓名) Values('0001020','周小华')"
  CnB.Execute Sqlstr
End Sub

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?