📄 删除用户.frm
字号:
VERSION 5.00
Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX"
Begin VB.Form moveuser
BorderStyle = 1 'Fixed Single
Caption = "删除用户"
ClientHeight = 2520
ClientLeft = 5535
ClientTop = 4650
ClientWidth = 3885
LinkTopic = "Form1"
MaxButton = 0 'False
ScaleHeight = 2520
ScaleWidth = 3885
Begin MSAdodcLib.Adodc Adodc1
Height = 330
Left = 480
Top = 2400
Visible = 0 'False
Width = 1200
_ExtentX = 2117
_ExtentY = 582
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 = "Provider=MSDASQL.1;Persist Security Info=False;User ID=sa;Data Source=stu_manage"
OLEDBString = "Provider=MSDASQL.1;Persist Security Info=False;User ID=sa;Data Source=stu_manage"
OLEDBFile = ""
DataSourceName = ""
OtherAttributes = ""
UserName = "sa"
Password = "manager"
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 Command2
Caption = "返回"
Height = 375
Left = 1080
TabIndex = 3
Top = 1920
Width = 855
End
Begin VB.CommandButton Command1
Caption = "删 除"
Height = 375
Left = 2280
TabIndex = 2
Top = 1920
Width = 855
End
Begin VB.ComboBox Combo1
Height = 300
Left = 1080
Style = 2 'Dropdown List
TabIndex = 1
Top = 960
Width = 1695
End
Begin VB.Label Label3
Caption = "Label3"
Height = 255
Left = 120
TabIndex = 5
Top = 240
Width = 2775
End
Begin VB.Label Label2
Height = 375
Left = 600
TabIndex = 4
Top = 1440
Width = 3015
End
Begin VB.Label Label1
Caption = "请选择您要删除的用户名"
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 720
TabIndex = 0
Top = 600
Width = 2775
End
End
Attribute VB_Name = "moveuser"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'定义全局变量
Option Explicit
Public rs As New ADODB.Recordset
Public adoconn As New ADODB.Connection 'Connection 对象代表了打开与数据源的连接。
Public deluser As String
'显示管理员选择的用户名
Private Sub Combo1_click()
deluser = Combo1.Text
Label2.Caption = "您选择的用户名是:" & deluser
End Sub
'删除用户
Private Sub Command1_Click()
If Len(deluser) = 0 Then
MsgBox "请先选择你要删除的用户名!"
Combo1.SetFocus
Exit Sub
End If
'确认对话框:有“是”与“否”两种选择
Dim r As Integer
r = MsgBox("您确认要删除该用户吗?", 4 + 32 + 0, "删除用户")
'选择是
If r = 6 Then
rs.Open "delete from admin where id='" & deluser & "'", adoconn
deluser = ""
Label2.Caption = ""
MsgBox "删除用户成功!"
Call combo
Combo1.SetFocus
'选择否
ElseIf r = 7 Then
deluser = ""
Label2.Caption = ""
Call combo
Combo1.Text = ""
Exit Sub
End If
End Sub
'返回用户管理界面
Private Sub Command2_Click()
adoconn.Close
Unload Me
manage.Show
End Sub
'打开窗体时,打开数据库
Private Sub Form_Load()
adoconn.ConnectionString = Adodc1.ConnectionString 'Adodc1为窗体中的ADO控件,并已成功连接数据库
adoconn.Open
Set rs = New ADODB.Recordset
rs.CursorLocation = adUseClient
rs.CursorType = adOpenStatic
rs.LockType = adLockBatchOptimistic
Call combo
End Sub
'给组合框中添加用户名
Private Sub combo()
Combo1.Clear
rs.Open "select * from admin", adoconn
Label3.Caption = "数据库中共有" & rs.RecordCount & "个用户"
Dim i As Integer
If rs.RecordCount = 0 Then
Label3.Caption = "数据库中没有用户信息!"
Else
rs.MoveFirst
For i = 0 To rs.RecordCount - 1
Combo1.AddItem rs.Fields("id")
rs.MoveNext
Next i
End If
rs.Close
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -