LH的登录存储过程调用
存储过程:LH_LoginJudge
1set ANSI_NULLS ON
2set QUOTED_IDENTIFIER ON
3go
4
5-- =============================================
6-- Author: <g>
7-- Create date: <090109>
8-- Description: <验证登录的存储过程>
9-- =============================================
10ALTER PROCEDURE [dbo].[LH_LoginJudge]
11 (@LoginName[nvarchar] (20),
12 @LoginPass[nvarchar] (20),
13 @IsRight [int] output
14 )
15AS
16BEGIN
17 -- SET NOCOUNT ON added to prevent extra result sets from
18 -- interfering with SELECT statements.
19 SET NOCOUNT ON;
20
21 -- Insert statements for procedure here
22 IF NOT EXISTS(select UserID from users where username=@LoginName and userpass=@LoginPass)
23 begin
24 set @IsRight =0 --表示登录不成功
25 end
26 else
27 begin
28 set @IsRight =1 --表示登录成功
29 end
30
31return
32END
33
2set QUOTED_IDENTIFIER ON
3go
4
5-- =============================================
6-- Author: <g>
7-- Create date: <090109>
8-- Description: <验证登录的存储过程>
9-- =============================================
10ALTER PROCEDURE [dbo].[LH_LoginJudge]
11 (@LoginName[nvarchar] (20),
12 @LoginPass[nvarchar] (20),
13 @IsRight [int] output
14 )
15AS
16BEGIN
17 -- SET NOCOUNT ON added to prevent extra result sets from
18 -- interfering with SELECT statements.
19 SET NOCOUNT ON;
20
21 -- Insert statements for procedure here
22 IF NOT EXISTS(select UserID from users where username=@LoginName and userpass=@LoginPass)
23 begin
24 set @IsRight =0 --表示登录不成功
25 end
26 else
27 begin
28 set @IsRight =1 --表示登录成功
29 end
30
31return
32END
33
运行的方法
1 public bool userLoginJudge2()
2 //使用存储过程
3 {
4 int IsRight;
5 SqlConnection conn = new SqlConnection(connstring);
6 SqlCommand cmd = new SqlCommand("LH_LoginJudge", conn);
7 cmd.CommandType = CommandType.StoredProcedure;
8 cmd.Parameters.Add("@LoginName", SqlDbType.NChar);
9 cmd.Parameters.Add("@LoginPass",SqlDbType.NChar);
10 cmd.Parameters.Add("@IsRight", SqlDbType.Int);
11 cmd.Parameters["@LoginName"].Value = _LoginName;
12 cmd.Parameters["@LoginPass"].Value = _LoginPass;
13 cmd.Parameters["@IsRight"].Value = 0;
14 cmd.Parameters["@IsRight"].Direction = ParameterDirection.Output;
15 conn.Open();
16 cmd.ExecuteNonQuery();
17 IsRight = (int)cmd.Parameters["@IsRight"].Value;
18 conn.Close();
19 return Convert.ToBoolean(IsRight);
20 }
2 //使用存储过程
3 {
4 int IsRight;
5 SqlConnection conn = new SqlConnection(connstring);
6 SqlCommand cmd = new SqlCommand("LH_LoginJudge", conn);
7 cmd.CommandType = CommandType.StoredProcedure;
8 cmd.Parameters.Add("@LoginName", SqlDbType.NChar);
9 cmd.Parameters.Add("@LoginPass",SqlDbType.NChar);
10 cmd.Parameters.Add("@IsRight", SqlDbType.Int);
11 cmd.Parameters["@LoginName"].Value = _LoginName;
12 cmd.Parameters["@LoginPass"].Value = _LoginPass;
13 cmd.Parameters["@IsRight"].Value = 0;
14 cmd.Parameters["@IsRight"].Direction = ParameterDirection.Output;
15 conn.Open();
16 cmd.ExecuteNonQuery();
17 IsRight = (int)cmd.Parameters["@IsRight"].Value;
18 conn.Close();
19 return Convert.ToBoolean(IsRight);
20 }
运行的代码
1 userLogin ulg = new userLogin(TextBox1.Text, TextBox2.Text);
2 if (ulg.userLoginJudge2())
3 { Label1.Text = "ok"; }
4 else
5 { Label1.Text = "no"; }
2 if (ulg.userLoginJudge2())
3 { Label1.Text = "ok"; }
4 else
5 { Label1.Text = "no"; }