?? form1.frm
字號:
VERSION 5.00
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX"
Begin VB.Form Form1
Caption = "數(shù)據(jù)庫編程演示"
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 + -