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

📄 form1.frm

📁 是我的个人设计站长快让我通过啊
💻 FRM
字号:
VERSION 5.00
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX"
Begin VB.Form Form1 
   Caption         =   "数据库编程演示"
   ClientHeight    =   4440
   ClientLeft      =   165
   ClientTop       =   855
   ClientWidth     =   10935
   LinkTopic       =   "Form1"
   ScaleHeight     =   4440
   ScaleWidth      =   10935
   StartUpPosition =   3  'Windows Default
   Begin VB.TextBox Text5 
      Height          =   375
      Left            =   8520
      TabIndex        =   10
      Top             =   3000
      Width           =   1335
   End
   Begin VB.TextBox Text4 
      Height          =   375
      Left            =   8520
      TabIndex        =   9
      Top             =   2400
      Width           =   1335
   End
   Begin VB.TextBox Text3 
      Height          =   375
      Left            =   8520
      TabIndex        =   8
      Top             =   1680
      Width           =   1335
   End
   Begin VB.TextBox Text2 
      Height          =   375
      Left            =   8520
      TabIndex        =   7
      Top             =   960
      Width           =   1335
   End
   Begin VB.TextBox Text1 
      Height          =   375
      Left            =   8520
      TabIndex        =   5
      Top             =   360
      Width           =   1335
   End
   Begin VB.CommandButton Command4 
      Caption         =   "退出"
      Height          =   495
      Left            =   5040
      TabIndex        =   4
      Top             =   3720
      Width           =   975
   End
   Begin VB.CommandButton Command3 
      Caption         =   "插入"
      Height          =   495
      Left            =   3480
      TabIndex        =   3
      Top             =   3720
      Width           =   975
   End
   Begin VB.CommandButton Command2 
      Caption         =   "删除"
      Height          =   495
      Left            =   1800
      TabIndex        =   2
      Top             =   3720
      Width           =   975
   End
   Begin VB.CommandButton Command1 
      Caption         =   "查询"
      Height          =   495
      Left            =   360
      TabIndex        =   1
      Top             =   3720
      Width           =   975
   End
   Begin MSFlexGridLib.MSFlexGrid MSFlexGrid1 
      Height          =   3015
      Left            =   480
      TabIndex        =   0
      Top             =   360
      Width           =   6135
      _ExtentX        =   10821
      _ExtentY        =   5318
      _Version        =   393216
      Rows            =   1
      Cols            =   6
   End
   Begin VB.Label Label5 
      Caption         =   "系"
      Height          =   375
      Left            =   7440
      TabIndex        =   14
      Top             =   3240
      Width           =   855
   End
   Begin VB.Label Label4 
      Caption         =   "年龄"
      Height          =   375
      Left            =   7440
      TabIndex        =   13
      Top             =   2520
      Width           =   855
   End
   Begin VB.Label Label3 
      Caption         =   "性别"
      Height          =   375
      Left            =   7440
      TabIndex        =   12
      Top             =   1800
      Width           =   495
   End
   Begin VB.Label Label2 
      Caption         =   "姓名"
      Height          =   375
      Left            =   7440
      TabIndex        =   11
      Top             =   1080
      Width           =   615
   End
   Begin VB.Label Label1 
      Caption         =   "学号"
      Height          =   375
      Left            =   7440
      TabIndex        =   6
      Top             =   480
      Width           =   735
   End
   Begin VB.Menu select 
      Caption         =   "查询"
   End
   Begin VB.Menu delete 
      Caption         =   "删除"
   End
   Begin VB.Menu insert 
      Caption         =   "插入"
   End
   Begin VB.Menu exit 
      Caption         =   "退出"
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()

 Dim cnn As ADODB.Connection
   Dim rst As ADODB.Recordset
   Dim ConnectString As String
   Dim SQL As String
    Dim sTokens() As String
  
   ConnectString = "FileDSN=my_stu.dsn;UID=sa;PWD=666666"
   SQL = "select * from  学生表"
   Set cnn = New ADODB.Connection
   cnn.Open ConnectString
   'cnn.Execute (SQL)
        
      Set rst = New ADODB.Recordset
      rst.Open Trim$(SQL), cnn, _
         adOpenKeyset, _
         adLockOptimistic
       MsgString = "查询到" & rst.RecordCount & _
         " 条记录 "
  ' MsgBox (MsgString)
   
 Dim j As Integer
  j = 1
   MSFlexGrid1.Rows = 1
        Do While Not rst.EOF
        MSFlexGrid1.Rows = MSFlexGrid1.Rows + 1
            MSFlexGrid1.Row = j
            For i = 1 To rst.Fields.Count
               MSFlexGrid1.Col = i
               MSFlexGrid1.Text = Trim(rst.Fields(i - 1))
            Next i
            rst.MoveNext
            j = j + 1
        Loop
    rst.Close
ExecuteSQL_Exit:
   Set rst = Nothing
   Set cnn = Nothing

End Sub

Private Sub Command2_Click()
Dim cnn As ADODB.Connection
   Dim rst As ADODB.Recordset
   Dim ConnectString As String
   Dim SQL As String
    
  
   ConnectString = "FileDSN=my_stu.dsn;UID=sa;PWD=666666"
   SQL = "select * from 学生表 where 学号='" & Trim(InputBox("请输入学号:")) & "'"

   Set cnn = New ADODB.Connection
   cnn.Open ConnectString
   
   'cnn.Execute (SQL)
     
      Set rst = New ADODB.Recordset
      rst.Open Trim$(SQL), cnn, _
         adOpenKeyset, _
         adLockOptimistic
       MsgString = "查询到" & rst.RecordCount & _
         " 条记录 "
         MsgBox (MsgString)
      If rst.EOF Then
MsgBox ("没有此条目!")

Else
Form1.Text1.Text = rst.Fields("学号")
msg1 = MsgBox("真的需要删除" & rst.Fields("学号") & "_" & rst.Fields("姓名") & " ?", vbOKCancel, "删除")
Form1.Text1.Text = rst.Fields("学号")
If msg1 = vbOK Then
cnn.Execute ("delete from 学生表 where 学号='" & Trim(Form1.Text1.Text) & "'")
Form1.Text1.Text = ""
MsgBox ("条目成功删除!")
End If
End If
    rst.Close
ExecuteSQL_Exit:
   Set rst = Nothing
   Set cnn = Nothing

Call Command1_Click

End Sub

Private Sub Command3_Click()


Dim cnn As ADODB.Connection
   Dim rst As ADODB.Recordset
   Dim ConnectString As String
   Dim SQL As String
    
  
   ConnectString = "FileDSN=my_stu.dsn;UID=sa;PWD=666666"
   SQL = "select * from 学生表 where 学号='" & Trim(Form1.Text1.Text) & "'"

   Set cnn = New ADODB.Connection
   cnn.Open ConnectString
   
   'cnn.Execute (SQL)
     
      Set rst = New ADODB.Recordset
      rst.Open Trim$(SQL), cnn, _
         adOpenKeyset, _
         adLockOptimistic
       MsgString = "查询到" & rst.RecordCount & _
         " 条记录 "
         MsgBox (MsgString)
      If rst.EOF Then
      SQL = "insert into 学生表 values('" & Trim(Form1.Text1.Text) & "','" & Trim(Form1.Text2.Text) & "','" & Trim(Form1.Text3.Text) & "','" & Trim(Form1.Text4.Text) & "','" & Trim(Form1.Text5.Text) & "')"
    cnn.Execute (SQL)
    
    Form1.Text1.Text = ""
    Form1.Text2.Text = ""
    Form1.Text3.Text = ""
    Form1.Text4.Text = ""
    Form1.Text5.Text = ""
    
    Else
    MsgBox ("本学员已经存在了!")

End If




End Sub

Private Sub Command4_Click()
Unload Me

End Sub

Private Sub delete_Click()
Call Command2_Click
End Sub

Private Sub exit_Click()
Call Command4_Click
End Sub

Private Sub Form_Load()

i = 0

 With MSFlexGrid1

.Row = i
.Col = 0
'MSFlexGrid1.Text = i
.Col = 1
.Text = "学号"
.Col = 2
.Text = "姓名"
.Col = 3
.Text = "性别"
.Col = 4
.Text = "年龄"
.Col = 5
.Text = "系"

End With

End Sub
Private Sub ShowData()
    
    Dim j As Integer
    Dim i As Integer
    Dim MsgText As String

  
    Set mrc = ExecuteSQL(txtSQL, MsgText)
        With msgList
        .Rows = 1
        
        Do While Not mrc.EOF
            .Rows = .Rows + 1
            For i = 1 To mrc.Fields.Count
                If Not IsNull(Trim(mrc.Fields(i - 1))) Then
                Select Case mrc.Fields(i - 1).Type
                    Case adDBDate
                        .TextMatrix(.Rows - 1, i) = Format(mrc.Fields(i - 1) & "", "yyyy-mm-dd")
                    Case Else
                        .TextMatrix(.Rows - 1, i) = mrc.Fields(i - 1) & ""
                End Select
                End If
            Next i
            mrc.MoveNext
        Loop
        
          
    End With
    mrc.Close
    
    
End Sub

Private Sub insert_Click()
Call Command3_Click
End Sub

Private Sub select_Click()
Call Command1_Click
End Sub

⌨️ 快捷键说明

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