?? form2.frm
字號:
VERSION 5.00
Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX"
Begin VB.Form frmAddGrade
BackColor = &H00C0C0C0&
Caption = "Form2"
ClientHeight = 3165
ClientLeft = 60
ClientTop = 345
ClientWidth = 5385
LinkTopic = "Form2"
ScaleHeight = 3165
ScaleWidth = 5385
StartUpPosition = 3 '窗口缺省
Begin VB.ComboBox Combo1
BackColor = &H00C0FFFF&
Height = 300
Left = 1200
TabIndex = 7
Top = 480
Width = 2175
End
Begin VB.ComboBox Combo2
BackColor = &H00C0FFFF&
Height = 300
ItemData = "Form2.frx":0000
Left = 1200
List = "Form2.frx":0002
TabIndex = 6
Top = 960
Width = 2175
End
Begin VB.TextBox Text2
BackColor = &H00C0FFFF&
Height = 300
Left = 1200
TabIndex = 5
Top = 1440
Width = 2175
End
Begin MSAdodcLib.Adodc Adodc1
Height = 375
Left = 480
Top = 2400
Visible = 0 'False
Width = 1935
_ExtentX = 3413
_ExtentY = 661
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=db5.mdb;Persist Security Info=False"
OLEDBString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db5.mdb;Persist Security Info=False"
OLEDBFile = ""
DataSourceName = ""
OtherAttributes = ""
UserName = ""
Password = ""
RecordSource = "學生與課程"
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 VB.CommandButton Command4
Caption = "退出"
Height = 375
Left = 3960
TabIndex = 4
Top = 2280
Width = 1335
End
Begin VB.CommandButton Command3
Caption = "刪除"
Height = 375
Left = 3960
TabIndex = 3
Top = 1200
Width = 1335
End
Begin VB.CommandButton Command1
Caption = "添加"
Height = 375
Left = 3960
TabIndex = 2
Top = 360
Width = 1335
End
Begin VB.Label Label7
BackColor = &H00C0C0C0&
Caption = "課程號:"
Height = 255
Left = 240
TabIndex = 9
Top = 480
Width = 735
End
Begin VB.Label Label6
Caption = "Label6"
Height = 15
Left = 2040
TabIndex = 8
Top = 1560
Width = 1215
End
Begin VB.Label Label2
BackColor = &H00C0C0C0&
Caption = "課程名稱:"
ForeColor = &H00000000&
Height = 375
Left = 240
TabIndex = 1
Top = 960
Width = 975
End
Begin VB.Label Label1
BackColor = &H00C0C0C0&
Caption = "學號:"
ForeColor = &H00000000&
Height = 375
Left = 240
TabIndex = 0
Top = 1440
Width = 855
End
End
Attribute VB_Name = "frmAddGrade"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim rs As New ADODB.Recordset
Private Sub Command1_Click()
'On Error GoTo errh
If Combo1.Text <> "" Then
If Combo2.Text <> "" Then
If Text2.Text <> "" Then
'If Text3.Text <> "" Then
'If Combo3.Text <> "" Then
If checkclass Then
If checkcourse Then
' If match = True Then
With Adodc1.Recordset
.AddNew
.Fields("課程號").Value = Combo1.Text
.Fields("學號").Value = Text2.Text
.Fields("課程名稱").Value = Combo2.Text
.Update
End With
MsgBox "添加成功!"
Combo1.Text = ""
Combo2.Text = ""
'Combo3.Text = ""
Text2.Text = ""
' Text3.Text = ""
Else
MsgBox "沒有這個課程,不能添加!"
' Combo3.Text = ""
Text2.Text = ""
' Text3.Text = ""
Combo1.Text = ""
Combo2.Text = ""
Combo1.SetFocus
' End If
' "
' Text3.SetFocus
End If
'Else
'MsgBox "備注不能為空,請輸入備注!"
End If
Else
MsgBox "學號不能為空,請輸入學號!"
Text2.SetFocus
End If
Else
MsgBox "課程名稱不能為空,請輸入課程名稱!"
Combo2.SetFocus
End If
Else
MsgBox "課程號不能為空,請輸入課程號!"
Combo1.SetFocus
End If
Exit Sub
'errh:
'MsgBox Err.Description
End Sub
Private Sub Command3_Click()
On Error GoTo errh
If MsgBox("你的操作將會刪除當前的紀錄,你確信嗎?", vbOKCancel, "警告") = vbOK Then
'Combo1.DataSource = Adodc2
'Combo2.DataSource = Adodc2
'Combo3.DataSource = Adodc2
'Text2.DataSource = Adodc2
'Text3.DataSource = Adodc2
'SD = True
'Adodc1.Recordset.Delete
' Adodc1.Recordset.MoveFirst
' Dim str As String
' str = " delete from 學生與課程 " 'where 課程號='" & Trim(Combo1.Text) & "' and 課程名稱= '" & Trim(Combo2.Text) & "' and 學號= '" & Trim(Text2.Text) & "' and 成績= '" & Trim(Text3.Text) & "' "
' Dim cmd As New ADODB.Command
' cmd.ActiveConnection = cn
'
' cmd.CommandText = str
' cmd.CommandType = adCmdText
'
' cmd.Execute
'rs.Open
' Dim rs1 As New ADODB.Recordset
'Set rs1 = Nothing
'rs1.CursorType = adOpenDynamic
'rs1.LockType = adLockOptimistic
rs.Open "SELECT * FROM 學生與課程 WHERE 課程名稱='" & Trim(Combo2.Text) & "'AND 課程號='" & Trim(Combo1.Text) & "' and 學號='" & Trim(Text2.Text) & "'", cn, adOpenDynamic, adLockOptimistic, adCmdText
'Set rs1 = cn.Execute("SELECT * FROM 學生與課程 WHERE 課程名稱='" & Trim(Combo2.Text) & "'AND 課程號='" & Trim(Combo1.Text) & "' and 學號='" & Trim(Text2.Text) & "' And 成績 = '" & Trim(Text3.Text) & "' ")
'If Adodc2.Recordset.EOF Then
If rs.EOF Then
'Adodc2.Recordset.Close
rs.Close
MsgBox "沒有這條記錄,無法刪除!"
Exit Sub
End If
'Adodc2.Recordset.Delete
'Adodc2.Recordset.Update
'Adodc2.Recordset.Close
rs.Delete
rs.Update
rs.Close
MsgBox "刪除成功!"
Text2.Text = ""
' Text3.Text = ""
Combo1.Text = ""
Combo2.Text = ""
' Combo3.Text = ""
End If
Exit Sub
errh:
rs.Close
MsgBox Err.Description
End Sub
Private Sub Command4_Click()
Unload Me
End Sub
Private Sub Form_Load()
On Error GoTo errh
MakeCenter frmAddGrade
Set rs = cn.Execute("SELECT 課程名稱,課程號 FROM 課程")
rs.MoveFirst
Do
Combo1.AddItem rs.Fields(1).Value
Combo2.AddItem rs.Fields(0).Value
rs.MoveNext
Loop Until rs.EOF
'///////////////////////////////////
Exit Sub
errh:
rs.Close
MsgBox Err.Description
End Sub
Private Function checkcourse() As Boolean
On Error GoTo errh
Set rs = cn.Execute("select * from 課程 where 課程號='" & Trim(Combo1.Text) & "' and 課程名稱='" & Trim(Combo2.Text) & "'")
'If Adodc2.Recordset.EOF Then
'Adodc2.Recordset.Close
If rs.EOF Then
rs.Close
checkcourse = False
Exit Function
End If
checkcourse = True
rs.Close
Exit Function
errh:
rs.Close
MsgBox Err.Description
End Function
Private Function checkclass() As Boolean '檢測添加的課程是否重復
On Error GoTo errh
' Adodc2.ConnectionString = "DRIVER={Microsoft Access Driver (*.mdb)};" & _
"DBQ=db5.MDB;" & _
"DefaultDir=" & CheckPath(App.path) & ";" & _
"UID=;PWD=;"
Set rs = cn.Execute("SELECT 課程名稱 FROM 學生與課程 WHERE 課程名稱='" & Trim(Combo2.Text) & "'AND 課程號='" & Trim(Combo1.Text) & "' and 學號='" & Trim(Text2.Text) & "' And 成績 Is Not Null ")
' Adodc2.RecordSource = "select * from 課程 where 課程號='" & Trim(Text1.Text) & "' and 課程名稱='" & Trim(Text2.Text) & "' "
If rs.EOF Then
rs.Close
checkclass = True
Exit Function
End If
checkclass = False
rs.Close
Exit Function
errh:
rs.Close
MsgBox Err.Description
End Function
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -