📄 adddep.frm
字号:
VERSION 5.00
Object = "{CE671F01-259E-40DA-92FE-95803E2ECBB5}#1.0#0"; "SmartXPButton.ocx"
Object = "{CDE57A40-8B86-11D0-B3C6-00A0C90AEA82}#1.0#0"; "MSDATGRD.OCX"
Begin VB.Form adddep
BackColor = &H00E7DFE7&
Caption = "添加院系"
ClientHeight = 4515
ClientLeft = 60
ClientTop = 450
ClientWidth = 6945
Icon = "adddep.frx":0000
LinkTopic = "Form1"
ScaleHeight = 4515
ScaleWidth = 6945
StartUpPosition = 2 '屏幕中心
Begin VB.TextBox Text1
Height = 375
Left = 1200
TabIndex = 0
Top = 1680
Width = 1215
End
Begin VB.TextBox Text2
Height = 375
Left = 1200
TabIndex = 1
Top = 2520
Width = 1335
End
Begin SmartXPButton.XpButton XpButton2
Height = 495
Left = 4320
TabIndex = 2
Top = 3480
Width = 1215
_ExtentX = 2143
_ExtentY = 873
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "宋体"
Size = 9
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Caption = "取消(&T)"
PictureSmoothBackColor= 15460844
ButtonPicture = "adddep.frx":0A02
End
Begin SmartXPButton.XpButton XpButton1
Height = 495
Left = 1680
TabIndex = 3
Top = 3480
Width = 1215
_ExtentX = 2143
_ExtentY = 873
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "宋体"
Size = 9
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Caption = "添加(&T)"
PictureSmoothBackColor= 15460844
ButtonPicture = "adddep.frx":1414
End
Begin MSDataGridLib.DataGrid DataGrid1
Height = 2250
Left = 2880
TabIndex = 4
Top = 960
Width = 3735
_ExtentX = 6588
_ExtentY = 3969
_Version = 393216
AllowUpdate = 0 'False
BackColor = 16777215
ForeColor = -2147483642
HeadLines = 1
RowHeight = 18
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
Begin VB.Label Label1
BackStyle = 0 'Transparent
Caption = "添加院系信息"
BeginProperty Font
Name = "隶书"
Size = 21.75
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H80000002&
Height = 495
Left = 2280
TabIndex = 7
Top = 240
Width = 3015
End
Begin VB.Label Label2
BackStyle = 0 'Transparent
Caption = "院系编号:"
Height = 495
Left = 360
TabIndex = 6
Top = 1800
Width = 855
End
Begin VB.Label Label3
BackStyle = 0 'Transparent
Caption = "院系名称"
Height = 495
Left = 360
TabIndex = 5
Top = 2640
Width = 855
End
End
Attribute VB_Name = "adddep"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim myconn As New ADODB.Connection
Dim str As String
Dim MyRs As New ADODB.Recordset
Private Sub Form_Load()
Set myconn = New ADODB.Connection
myconn.ConnectionString = "driver={SQL Server};" & _
"server=(local);uid=sa;pwd=;database=student_info"
myconn.Open
'***** 使用Recordset对象的Open方法创建记录集 *****
'MyRs.Open "manager", MyConn, adOpenStatic, adLockOptimistic, adCmdTable
Set MyRs = New ADODB.Recordset
With MyRs
.Source = "department"
.ActiveConnection = myconn
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open , , , , adCmdTable
End With
Set DataGrid1.DataSource = MyRs
DataGrid1.Columns(0).Caption = "院系编号"
DataGrid1.Columns(1).Caption = "院系名称"
DataGrid1.Columns(0).Width = 800
DataGrid1.Columns(1).Width = 1400
End Sub
Private Sub XpButton1_Click()
On Error GoTo DbnotOpen
If Len(Trim(Text1.Text)) <> 0 And Len(Trim(Text2.Text)) <> 0 Then
With MyRs
.AddNew
.Fields("ID") = Trim(Text1.Text)
.Fields("NAME") = Trim(Text2.Text)
.Update
End With
MsgBox "院系信息已添加成功!", vbOKOnly + vbInformation, "提示信息"
Text1.Text = ""
Text2.Text = ""
Text1.SetFocus
Set DataGrid1.DataSource = MyRs
DataGrid1.Columns(0).Caption = "院系编号"
DataGrid1.Columns(1).Caption = "院系名称"
DataGrid1.Columns(0).Width = 800
DataGrid1.Columns(1).Width = 1400
Else
MsgBox "院系信息没有填写完整!", vbOKOnly + vbExclamation, "错误提示"
End If
DbnotOpen:
If Err = -2147217873 Then
'Set myconn = Nothing
MsgBox "数据库中存在重复的记录!" & vbCrLf & vbCrLf & "添加院系失败!", vbOKOnly + vbExclamation, "错误提示"
Set MyRs = New ADODB.Recordset
With MyRs
.Source = "department"
.ActiveConnection = myconn
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open , , , , adCmdTable
End With
Set DataGrid1.DataSource = MyRs
DataGrid1.Columns(0).Caption = "院系编号"
DataGrid1.Columns(1).Caption = "院系名称"
DataGrid1.Columns(0).Width = 800
DataGrid1.Columns(1).Width = 1400
End If
If Err = -2147217887 Then
MsgBox " 输入的院系编号或院系名称长度越界,请重新输入!", vbInformation, "提示信息"
Text1.SetFocus
Text1.Text = ""
Text2.Text = ""
Set MyRs = New ADODB.Recordset
With MyRs
.Source = "department"
.ActiveConnection = myconn
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open , , , , adCmdTable
End With
Set DataGrid1.DataSource = MyRs
DataGrid1.Columns(0).Caption = "院系编号"
DataGrid1.Columns(1).Caption = "院系名称"
DataGrid1.Columns(0).Width = 800
DataGrid1.Columns(1).Width = 1400
Exit Sub
End If
End Sub
Private Sub XpButton2_Click()
MyRs.Close
myconn.Close
Unload Me
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -