VB接SQL登录代码[教材]
在模块里定义:
Public con As New ADODB.Connection
Public rs As New ADODB.Recordset
Public Function connstring() As String
connstring = "filedsn=文件名.dsn;user id=SQL登录名;password=SQL登录密码;"
End Function
Private Sub Command1_Click()
Set con = New ADODB.Connection
con.ConnectionString = connstring
con.Open
Dim pwd As String
If Trim(Text1.Text = "") Then
MsgBox "用户名不能为空,请输入用户名~", vbOKOnly + vbExclamation, "警告"
Text1.SetFocus
Exit Sub
End If
If Trim(Text2.Text = "") Then
MsgBox "密码不能为空,请输入密码~", vbOKOnly + vbExclamation, "警告"
Text2.SetFocus
Exit Sub
End If
rs.Open "select * from
表
关于同志近三年现实表现材料材料类招标技术评分表图表与交易pdf视力表打印pdf用图表说话 pdf
名 where 字段='" + Trim$(Text1.Text) + "' and password='" +
Trim$(Text2.Text) + "' ", con, adOpenStatic, adLockOptimistic
If Not rs.EOF Then
pwd = Trim(rs.Fields("字段"))
End If
If Text2.Text = pwd Then
字段 = Text1.Text
Me.Hide
MDIForm1.Show ‘进入系统界面
Else
MsgBox "密码无效,请重新输入~", vbOKOnly + vbExclamation, "警告"
Text2.SetFocus
End If
Set rs = Nothing
Set con = Nothing
End Sub
Private Sub Command2_Click() Dim a, b, c
a = " 你选择了退出系统登录,退出将不会登录网购管理系统~"
b = "提示"
c = MsgBox(a, vbYesNo, b) If c = vbYes Then
End
End If