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

📄 form4.frm

📁 以VC为前台
💻 FRM
字号:
VERSION 5.00
Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX"
Begin VB.Form 添加学生记录 
   Caption         =   "添加学生记录"
   ClientHeight    =   5460
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   7830
   LinkTopic       =   "Form1"
   ScaleHeight     =   5460
   ScaleWidth      =   7830
   StartUpPosition =   3  'Windows Default
   Begin VB.Frame Frame2 
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   12
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   5055
      Left            =   240
      TabIndex        =   0
      Top             =   120
      Width           =   7215
      Begin VB.ComboBox Combo2 
         Height          =   315
         Left            =   4320
         TabIndex        =   10
         Text            =   "请选择班级"
         Top             =   1920
         Width           =   2055
      End
      Begin VB.TextBox Text3 
         Height          =   375
         Left            =   1320
         TabIndex        =   9
         Top             =   1920
         Width           =   1815
      End
      Begin MSAdodcLib.Adodc Adodc1 
         Height          =   375
         Left            =   840
         Top             =   4200
         Visible         =   0   'False
         Width           =   5415
         _ExtentX        =   9551
         _ExtentY        =   661
         ConnectMode     =   0
         CursorLocation  =   3
         IsolationLevel  =   -1
         ConnectionTimeout=   15
         CommandTimeout  =   30
         CursorType      =   3
         LockType        =   3
         CommandType     =   8
         CursorOptions   =   0
         CacheSize       =   50
         MaxRecords      =   0
         BOFAction       =   0
         EOFAction       =   0
         ConnectStringType=   1
         Appearance      =   1
         BackColor       =   -2147483643
         ForeColor       =   -2147483640
         Orientation     =   0
         Enabled         =   -1
         Connect         =   ""
         OLEDBString     =   ""
         OLEDBFile       =   ""
         DataSourceName  =   ""
         OtherAttributes =   ""
         UserName        =   ""
         Password        =   ""
         RecordSource    =   ""
         Caption         =   ""
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         _Version        =   393216
      End
      Begin VB.CommandButton Command1 
         Caption         =   "添加"
         Height          =   495
         Left            =   4320
         TabIndex        =   5
         Top             =   3120
         Width           =   975
      End
      Begin VB.CommandButton Command2 
         Caption         =   "退 出"
         Height          =   495
         Left            =   5520
         TabIndex        =   4
         Top             =   3120
         Width           =   975
      End
      Begin VB.TextBox Text1 
         Height          =   375
         Left            =   1320
         TabIndex        =   3
         Top             =   720
         Width           =   1815
      End
      Begin VB.TextBox Text2 
         Height          =   375
         Left            =   4320
         TabIndex        =   2
         Top             =   720
         Width           =   2055
      End
      Begin VB.ComboBox Combo1 
         Height          =   315
         Left            =   1320
         TabIndex        =   1
         Text            =   "请选择性别"
         Top             =   3240
         Width           =   1815
      End
      Begin VB.Label Label9 
         Caption         =   "班 级:"
         Height          =   255
         Left            =   3600
         TabIndex        =   12
         Top             =   2040
         Width           =   735
      End
      Begin VB.Label Label3 
         Caption         =   "姓 名:"
         Height          =   255
         Left            =   600
         TabIndex        =   11
         Top             =   2040
         Width           =   735
      End
      Begin VB.Label label1 
         Caption         =   "学 号:"
         Height          =   255
         Left            =   600
         TabIndex        =   8
         Top             =   840
         Width           =   735
      End
      Begin VB.Label Label5 
         Caption         =   "性 别:"
         Height          =   375
         Left            =   600
         TabIndex        =   7
         Top             =   3240
         Width           =   735
      End
      Begin VB.Label Label7 
         Caption         =   "年 龄:"
         Height          =   255
         Left            =   3600
         TabIndex        =   6
         Top             =   840
         Width           =   735
      End
   End
End
Attribute VB_Name = "添加学生记录"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Sub Command1_Click()
'以下代码用于出错处理
   
    Dim MsgText As String
    Dim sMeg As String
  If Text1.Text = "" Then
            sMeg = "学号不能为空"
            MsgBox sMeg, vbOKOnly + vbExclamation, "警告"
            Text1.SetFocus
            Exit Sub
  ElseIf Not IsNumeric(Text1.Text) Then
                MsgBox "请输入数字!", vbOKOnly + vbExclamation, "警告"
                Text1.SetFocus
                Text1.Text = ""
                Exit Sub
Else
    
            'Dim str As String
            Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset

Dim sSQL As String
Dim sOut As String
Dim Count As Integer
    
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset

' Set properties of the Connection.
cn.ConnectionString = "DSN=成绩查询;UID=sa;PWD=sa;"
cn.ConnectionTimeout = 30
cn.Open
sSQL = "SELECT * FROM xsxx where 学号=" & Text1.Text & ""
Set rs = cn.Execute(sSQL)
            If Not rs.BOF And Not rs.EOF Then
            MsgBox "该学号已存在!请重新输入!", vbOKOnly + vbExclamation, "警告"
            Text1.Text = ""
            Exit Sub
            End If
 End If

If Text3.Text = "" Then
            MsgBox "姓名不能为空,请重填!", vbOKOnly, "输入错误"
            Exit Sub
End If

 If Text2.Text = "" Then
            sMeg = "年龄不能为空"
            MsgBox sMeg, vbOKOnly + vbExclamation, "警告"
            Text1.SetFocus
            Exit Sub
  Else
            If Not IsNumeric(Text2.Text) Then
                MsgBox "请输入数字!", vbOKOnly + vbExclamation, "警告"
                Text2.SetFocus
                Text2.Text = ""
                Exit Sub
            End If
'If Len(Text2.Text) = 2 Then
'Text2.Text = Left(Text2.Text, 1) & Space(2) & Right(Text2.Text, 1)
End If


If Combo1.Text = "请选择性别" Then
            MsgBox "性别不能为空,请重填!", vbOKOnly, "输入错误"
            Exit Sub
End If

If Combo2.Text = "请选择班级" Then
            MsgBox "班级不能为空,请重填!", vbOKOnly, "输入错误"
            Exit Sub
End If

'以下代码用于向atabase.mdb数据库中的stsq表中添加记录
'Dim rs As Recordset
'Set rs = New Recordset
'rs.Open ("select * from xsxx "), db, adOpenDynamic, adLockOptimistic
'rs.MoveLast
'rs.AddNew
'rs.Fields(0) = Text1.Text
'rs.Fields(1) = Text3.Text
'rs.Fields(2) = Combo1.Text
'rs.Fields(3) = Text2.Text
'rs.Fields(4) = Combo2.Text
'rs.Update
'rs.Close
'db.Execute "insert into xsxx (学号,姓名,性别,年龄,班级) values(" & Text1.Text & ",'" & Text2.Text & " ','" & Combo1.Text & "' , " & Text4.Text & "," & Combo2.Text & ") "
cn.Execute "insert into xsxx (学号,姓名,班级,年龄,性别) values(" & Text1.Text & ",'" & Text3.Text & "'," & Combo2.Text & "," & Text2.Text & ",'" & Combo1.Text & "') "
MsgBox "学生信息增加成功", vbOKOnly, "学生信息增加成功"
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Combo1.Text = "请选择性别"
Combo2.Text = "请选择班级"
cn.Close

End Sub

Private Sub Command2_Click()
 Me.Hide
End Sub




Private Sub Frame1_DragDrop(Source As Control, X As Single, Y As Single)

End Sub

Private Sub Form_Load()
'Dim cn As New ADODB.Connection
'Set cn = New ADODB.Connection

Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset

Dim sSQL As String
Dim sOut As String
Dim Count As Integer
    
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset

' Set properties of the Connection.
cn.ConnectionString = "DSN=成绩查询;UID=sa;PWD=sa;"
cn.ConnectionTimeout = 30
cn.Open
sSQL = "SELECT DISTINCT 学号 FROM xsxx"
Set rs = cn.Execute(sSQL)

'Adodc1.ConnectionString = "Provider=SQLOLEDB.1;Password=sa;Persist Security Info=True;User ID=sa;Initial Catalog=成绩查询;Data Source=CCCCCC-YLGGS82E"
'Adodc1.RecordSource = "select * from xsxx"
'Set Text1.DataSource = Adodc1
'Text1.DataField = "学号"
'Set db = New Connection
'db.Open ("Provider=Microsoft.Jet.OLEDB.3.51;Data Source=" & App.Path & "\db2.mdb;")
'以下代码用于初始化COMBO1和COMBO2控件和DTPICKER1控件
Combo1.AddItem "男"
Combo1.AddItem "女"
Combo2.AddItem "1"
Combo2.AddItem "2"
Combo2.AddItem "3"
Combo2.AddItem "4"

'Combo1.AddItem "男"
'Combo1.AddItem "女"
cn.Close
End Sub

⌨️ 快捷键说明

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