![]() |
#2
cwa99582020-06-13 08:42
|

USE [WeMeet]
GO
/****** Object: StoredProcedure [dbo].[usp_Login] Script Date: 06/12/2020 17:08:02 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER proc [dbo].[usp_Login]
@name varchar(50),
@pwd varchar(50),
@isLogin int output
--0 登陆成功 1用户名为空 2密码为空 3用户名错误 4密码错误
as declare @times int --错误次数
--根据用户名是否存在
if(@name is null)
begin
set @isLogin=1
end
else
if (@pwd is null)
begin
set @isLogin=2
end
else
if exists(select * from [Player] where pName=@name)
begin
if exists(select * from [Player] where pName=@name and pPassword=@pwd)
begin
--用户名密码正确 登陆成功
set @isLogin=0
end
else
begin
--密码错误
set @isLogin=4
end
end
else
--用户名不存在
begin
set @isLogin= 3
end
vb代码

Private Sub Command1_Click()
Dim cmd As String, cc As Long
On Error GoTo ErrorHandler
If Trim(Text1.Text) = "" Then
P1: MsgBox "用户名不可以为空", vbOKOnly: Exit Sub
End If
If Trim(Text2.Text) = "" Then
P2: MsgBox "密码不可以为空", vbOKOnly: Exit Sub
End If
cmd = " begin tran "
cmd = cmd & " declare @name char(50),@pwd char(50),@isLogin int"
cmd = cmd & " set nocount on "
cmd = cmd & " SET @name='" & Trim(Text1.Text) & "' "
cmd = cmd & " SET @pwd ='" & Trim(Text2.Text) & "' "
cmd = cmd & " Exec usp_Login @name,@pwd,@isLogin"
cmd = cmd & " select @isLogin"
cmd = cmd & " if @isLogin=0 commit else rollback "
Adodc1.RecordSource = cmd
Adodc1.Refresh
If Not IsNull(Adodc1.Recordset.Fields(0)) Then
cc = Val(Adodc1.Recordset.Fields(0))
End If
If cc = 0 Then MsgBox "已成功登录", vbOKOnly: Phome.Show vbModal: Unload Me: Exit Sub
If cc = 1 Then GoTo P1
If cc = 2 Then GoTo P2
If cc = 3 Then MsgBox "用户名不存在", vbOKOnly: Exit Sub
If cc = 4 Then MsgBox "密码错误", vbOKOnly: Exit Sub
P0:
MsgBox "发生一个未知错误!", vbOKOnly: Exit Sub
ErrorHandler:
MsgBox (Err.Description & Chr(13) & Chr(10))
Resume P0
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
Private Sub Form_Load()
Text1.Text = ""
Text2.Text = ""
End Sub