📄 course_frm.frm
字号:
VERSION 5.00
Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX"
Object = "{CDE57A40-8B86-11D0-B3C6-00A0C90AEA82}#1.0#0"; "MSDATGRD.OCX"
Begin VB.Form course_frm
Caption = "课程信息管理"
ClientHeight = 5985
ClientLeft = 60
ClientTop = 345
ClientWidth = 7350
LinkTopic = "Form1"
ScaleHeight = 5985
ScaleWidth = 7350
StartUpPosition = 3 '窗口缺省
Begin VB.Frame Frame1
Caption = "查询方式"
Height = 1455
Left = 120
TabIndex = 17
Top = 2400
Width = 2895
Begin VB.OptionButton Option1
Caption = "按编号:"
Height = 255
Left = 240
TabIndex = 23
Top = 360
Value = -1 'True
Width = 1215
End
Begin VB.OptionButton Option2
Caption = "按课名:"
Height = 255
Left = 240
TabIndex = 22
Top = 720
Width = 1215
End
Begin VB.OptionButton Option3
Caption = "按学分:"
Height = 225
Left = 240
TabIndex = 21
Top = 1080
Width = 1215
End
Begin VB.TextBox Text1
Height = 270
Left = 1440
TabIndex = 20
Top = 360
Width = 1095
End
Begin VB.TextBox Text2
Height = 270
Left = 1440
TabIndex = 19
Top = 720
Width = 1095
End
Begin VB.TextBox Text3
Height = 270
Left = 1440
TabIndex = 18
Top = 1080
Width = 1095
End
End
Begin VB.Frame Frame2
Caption = "修改用户资料"
Height = 2655
Left = 3120
TabIndex = 5
Top = 2520
Width = 3975
Begin VB.TextBox Text4
Height = 270
Left = 960
TabIndex = 11
Top = 360
Width = 735
End
Begin VB.TextBox Text5
Height = 270
Left = 2640
TabIndex = 10
Top = 360
Width = 1095
End
Begin VB.TextBox Text6
Height = 270
Left = 960
TabIndex = 9
Top = 840
Width = 735
End
Begin VB.TextBox Text7
Height = 270
Left = 2640
TabIndex = 8
Top = 840
Width = 1095
End
Begin VB.TextBox Text8
Height = 615
Left = 840
TabIndex = 7
Top = 1440
Width = 2775
End
Begin VB.CommandButton Command5
Caption = "保存"
Height = 375
Left = 2760
TabIndex = 6
Top = 2160
Width = 855
End
Begin VB.Label Label2
Caption = "课程编号:"
Height = 255
Left = 120
TabIndex = 16
Top = 360
Width = 1095
End
Begin VB.Label Label3
Caption = "课程名称:"
Height = 255
Left = 1800
TabIndex = 15
Top = 360
Width = 975
End
Begin VB.Label Label4
Caption = "学时:"
Height = 255
Left = 120
TabIndex = 14
Top = 840
Width = 975
End
Begin VB.Label Label5
Caption = "学分:"
Height = 255
Left = 1800
TabIndex = 13
Top = 840
Width = 735
End
Begin VB.Label Label6
Caption = "备注:"
Height = 255
Left = 120
TabIndex = 12
Top = 1440
Width = 735
End
End
Begin VB.Frame Frame3
Caption = "操作"
Height = 1215
Left = 120
TabIndex = 0
Top = 3960
Width = 2895
Begin VB.CommandButton Command1
Caption = "查找"
Height = 375
Left = 240
TabIndex = 4
Top = 240
Width = 975
End
Begin VB.CommandButton Command2
Caption = "添加"
Height = 375
Left = 1440
TabIndex = 3
Top = 240
Width = 975
End
Begin VB.CommandButton Command3
Caption = "删除"
Height = 375
Left = 240
TabIndex = 2
Top = 720
Width = 975
End
Begin VB.CommandButton Command4
Caption = "退出"
Height = 375
Left = 1440
TabIndex = 1
Top = 720
Width = 975
End
End
Begin MSAdodcLib.Adodc Adodc1
Height = 330
Left = 6120
Top = 120
Visible = 0 'False
Width = 1200
_ExtentX = 2117
_ExtentY = 582
ConnectMode = 0
CursorLocation = 3
IsolationLevel = -1
ConnectionTimeout= 15
CommandTimeout = 30
CursorType = 3
LockType = 3
CommandType = 2
CursorOptions = 0
CacheSize = 50
MaxRecords = 0
BOFAction = 0
EOFAction = 0
ConnectStringType= 1
Appearance = 1
BackColor = -2147483643
ForeColor = -2147483640
Orientation = 0
Enabled = -1
Connect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\VB实习\DB1.MDB;Persist Security Info=False"
OLEDBString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\VB实习\DB1.MDB;Persist Security Info=False"
OLEDBFile = ""
DataSourceName = ""
OtherAttributes = ""
UserName = ""
Password = ""
RecordSource = "courseinfo"
Caption = "Adodc1"
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "宋体"
Size = 9
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
_Version = 393216
End
Begin MSDataGridLib.DataGrid DataGrid1
Bindings = "course_frm.frx":0000
Height = 1815
Left = 120
TabIndex = 24
Top = 480
Width = 7095
_ExtentX = 12515
_ExtentY = 3201
_Version = 393216
HeadLines = 1
RowHeight = 15
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
Alignment = 2 'Center
Caption = "课程信息添加/查询/修改/删除"
BeginProperty Font
Name = "宋体"
Size = 15
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 960
TabIndex = 25
Top = 120
Width = 5295
End
End
Attribute VB_Name = "course_frm"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim con As ADODB.Connection
Dim qn As String
Dim No As String
Private Sub Command1_Click()
Dim query1 As String
If Option1.Value = True Then
qn = "cno"
query1 = "SELECT * FROM courseinfo WHERE " & qn & " = '" & Text1 & "'"
End If
If Option2.Value = True Then
qn = "cname"
query1 = "SELECT * FROM courseinfo WHERE " & qn & " = '" & Text2 & "'"
End If
If Option3.Value = True Then
qn = "credit"
query1 = "SELECT * FROM courseinfo WHERE " & qn & " = '" & Text3 & "'"
End If
Dim rs As New ADODB.Recordset
rs.Open query1, con, adOpenForwardOnly, adLockReadOnly
'Set DataGrid1.DataSource = Nothing
If Not (rs.EOF And rs.BOF) Then
rs.MoveFirst
rs.MoveLast
End If
If rs.RecordCount > 0 Then
Set DataGrid1.DataSource = rs
MsgBox "总共查到" & rs.RecordCount & "记录", vbInformation
Else
MsgBox "没有找到记录,请重新输入查询数据", vbInformation
End If
End Sub
Private Sub Command2_Click()
Text4 = ""
Text5 = ""
Text6 = ""
Text7 = ""
Text8 = ""
End Sub
Private Sub Command3_Click()
If Option1.Value = True Then
qn = "cno"
txt = Text1.Text
End If
If Option2.Value = True Then
qn = "cname"
txt = Text2.Text
End If
If Option3.Value = True Then
qn = "credit"
txt = Text3.Text
End If
Adodc1.CommandType = adCmdText
Adodc1.RecordSource = "select * from course where " & qn & " = '" & txt & "' "
' Adodc1.Refresh
No = Adodc1.Recordset.Fields(0)
Dim myrs As New ADODB.Recordset
Dim query1 As String
query1 = "SELECT * FROM choice WHERE course = '" & Trim(No) & " '"
myrs.Open query1, con, adOpenForwardOnly, adLockReadOnly
' Set DataGrid1.DataSource = Nothing
If Not (myrs.EOF And myrs.BOF) Then
myrs.MoveFirst
myrs.MoveLast
End If
If myrs.RecordCount > 0 Then
MsgBox "不能删除、与其他表有相关数据联系!", vbInformation + vbOKOnly, "删除提示"
Else
MsgBox "能删除、与其他表没有相关数据联系!", vbInformation + vbOKOnly, "删除提示"
Adodc1.Recordset.Delete
End If
End Sub
Private Sub Command4_Click()
Unload Me
End Sub
Private Sub Command5_Click()
'保存记录
Dim myrs As New ADODB.Recordset
myrs.Open "SELECT * FROM courseinfo", con, adOpenDynamic, adLockOptimistic, adCmdText
myrs.AddNew
If Text4.Text = Empty Then
MsgBox "课程编号不能为空!"
Text4.SetFocus
Exit Sub
End If
If Text5.Text = Empty Then
MsgBox "课程名称不能为空!"
Text5.SetFocus
Exit Sub
End If
myrs.Fields(0) = Text4.Text
myrs.Fields(1) = Text5.Text
myrs.Fields(2) = Text6.Text
myrs.Fields(3) = Text7.Text
myrs.Fields(4) = Text8.Text
myrs.Update '调用Recordset对象Update方法保存数据
Set DataGrid1.DataSource = myrs
Text4.Text = Empty
Text5.Text = Empty
Text6.Text = Empty
Text7.Text = Empty
Text6.Text = Empty
MsgBox "添加成功!"
End Sub
Private Sub Form_Load()
Set con = New ADODB.Connection
con.ConnectionString = Adodc1.ConnectionString
con.CursorLocation = adUseClient
con.Open
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -