⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form_adofield.frm

📁 vb编程+从基础到实践光盘代码
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Frm_ADOField 
   Caption         =   "Form1"
   ClientHeight    =   3330
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   3795
   LinkTopic       =   "Form1"
   ScaleHeight     =   3330
   ScaleWidth      =   3795
   StartUpPosition =   3  '窗口缺省
   Begin VB.TextBox Text7 
      Height          =   270
      Left            =   960
      TabIndex        =   7
      Text            =   "Text1"
      Top             =   2400
      Width           =   2175
   End
   Begin VB.TextBox Text6 
      Height          =   270
      Left            =   960
      TabIndex        =   6
      Text            =   "Text1"
      Top             =   2040
      Width           =   2175
   End
   Begin VB.TextBox Text5 
      Height          =   270
      Left            =   960
      TabIndex        =   5
      Text            =   "Text1"
      Top             =   1680
      Width           =   2175
   End
   Begin VB.TextBox Text4 
      Height          =   270
      Left            =   960
      TabIndex        =   4
      Text            =   "Text1"
      Top             =   1320
      Width           =   2175
   End
   Begin VB.TextBox Text3 
      Height          =   270
      Left            =   960
      TabIndex        =   3
      Text            =   "Text1"
      Top             =   960
      Width           =   2175
   End
   Begin VB.TextBox Text2 
      Height          =   270
      Left            =   960
      TabIndex        =   2
      Text            =   "Text1"
      Top             =   600
      Width           =   2175
   End
   Begin VB.TextBox Text1 
      Height          =   270
      Left            =   960
      TabIndex        =   1
      Text            =   "Text1"
      Top             =   240
      Width           =   2175
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      Caption         =   "Label1"
      Height          =   180
      Index           =   6
      Left            =   240
      TabIndex        =   13
      Top             =   2400
      Width           =   540
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      Caption         =   "Label1"
      Height          =   180
      Index           =   5
      Left            =   240
      TabIndex        =   12
      Top             =   2040
      Width           =   540
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      Caption         =   "Label1"
      Height          =   255
      Index           =   4
      Left            =   240
      TabIndex        =   11
      Top             =   1680
      Width           =   615
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      Caption         =   "Label1"
      Height          =   180
      Index           =   3
      Left            =   240
      TabIndex        =   10
      Top             =   1320
      Width           =   540
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      Caption         =   "Label1"
      Height          =   180
      Index           =   2
      Left            =   240
      TabIndex        =   9
      Top             =   960
      Width           =   540
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      Caption         =   "Label1"
      Height          =   180
      Index           =   1
      Left            =   240
      TabIndex        =   8
      Top             =   600
      Width           =   540
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      Caption         =   "Label1"
      Height          =   180
      Index           =   0
      Left            =   240
      TabIndex        =   0
      Top             =   240
      Width           =   540
   End
End
Attribute VB_Name = "Frm_ADOField"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

Dim myConn As ADODB.Connection
Dim myRec As ADODB.Recordset

Private Sub Form_Load()
Dim ConnStr As String
Dim mySQL As String
Dim i As Integer
    Set myConn = New ADODB.Connection
    
    ConnStr = "Provider=SQLOLEDB.1;Persist Security Info=False;"
    ConnStr = ConnStr + "User ID=sa;Initial Catalog=图书馆管理系统;"
    ConnStr = ConnStr + "Data Source=(local)"
    
    myConn.ConnectionString = ConnStr
    
    myConn.Open  '打开Connection连接
    
    '创建RecordSet对象
    Set myRec = New ADODB.Recordset
    
    mySQL = "select * from 学生信息表"
    
    myRec.Open mySQL, myConn, 1, 3
    
    For i = 0 To myRec.Fields.Count - 1  '先显示所有的列名
        Label1(i).Caption = myRec.Fields(i).Name
    Next
    
    '显示字段值
    Text1.Text = myRec(0).Value
    Text2.Text = myRec.Fields(1).Value
    Text3.Text = myRec("年龄").Value
    Text4.Text = myRec.Fields("性别").Value
    
    Text5.Text = myRec(4)
    Text6.Text = myRec.Fields.Item(5)
    Text7.Text = myRec.Fields.Item(6).Value

End Sub

⌨️ 快捷键说明

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