方法一
public static AdoHelper helper = AdoHelper.CreateHelper("sqlDA");
public static string cs = WebConfigurationManager.AppSettings["SqlServerConnectionString"];
protected void Page_Load(object sender, EventArgs e)
{
IDataParameter[] parameters = helper.GetSpParameterSet(cs, "GetUName");
parameters[0].Value = 6;
parameters[1].Direction = ParameterDirection.ReturnValue;
IDataReader reader = helper.ExecuteReader(cs, "GetUName", parameters);
string data = parameters[1].Value.ToString();
Response.Write(data);
}
存储过程为:
Create PROCEDURE GetUName
(
@userid int
)
AS
declare @uname varchar(50)
SELECT @uname = UName from UserInfo where UserID = @userid
return 1
GO
public static string cs = WebConfigurationManager.AppSettings["SqlServerConnectionString"];
protected void Page_Load(object sender, EventArgs e)
{
IDataParameter[] parameters = helper.GetSpParameterSet(cs, "GetUName");
parameters[0].Value = 6;
parameters[1].Direction = ParameterDirection.ReturnValue;
IDataReader reader = helper.ExecuteReader(cs, "GetUName", parameters);
string data = parameters[1].Value.ToString();
Response.Write(data);
}
存储过程为:
Create PROCEDURE GetUName
(
@userid int
)
AS
declare @uname varchar(50)
SELECT @uname = UName from UserInfo where UserID = @userid
return 1
GO
方法二:
1public static AdoHelper helper = AdoHelper.CreateHelper("sqlDA");
2 public static string cs = WebConfigurationManager.AppSettings["SqlServerConnectionString"];
3
4 protected void Page_Load(object sender, EventArgs e)
5 {
6 IDataParameter[] parameters = helper.GetSpParameterSet(cs, "GetUName");
7 parameters[0].Value = 6;
8 parameters[1].Direction = ParameterDirection.Output;
9 IDataReader reader = helper.ExecuteReader(cs, "GetUName", parameters);
10 string data = (string)parameters[1].Value;
11 Response.Write(data);
12
13
14 }
15
16存储过程
17CREATE PROCEDURE GetUName
18 -- Add the parameters for the stored procedure here
19(
20@userid int,
21@uname varchar(50) OutPut
22)
23AS
24
25 -- SET NOCOUNT ON added to prevent extra result sets from
26 -- interfering with SELECT statements.
27 SET NOCOUNT ON;
28
29 -- Insert statements for procedure here
30 SELECT @uname = UName from UserInfo where UserID = @userid
31
32GO
2 public static string cs = WebConfigurationManager.AppSettings["SqlServerConnectionString"];
3
4 protected void Page_Load(object sender, EventArgs e)
5 {
6 IDataParameter[] parameters = helper.GetSpParameterSet(cs, "GetUName");
7 parameters[0].Value = 6;
8 parameters[1].Direction = ParameterDirection.Output;
9 IDataReader reader = helper.ExecuteReader(cs, "GetUName", parameters);
10 string data = (string)parameters[1].Value;
11 Response.Write(data);
12
13
14 }
15
16存储过程
17CREATE PROCEDURE GetUName
18 -- Add the parameters for the stored procedure here
19(
20@userid int,
21@uname varchar(50) OutPut
22)
23AS
24
25 -- SET NOCOUNT ON added to prevent extra result sets from
26 -- interfering with SELECT statements.
27 SET NOCOUNT ON;
28
29 -- Insert statements for procedure here
30 SELECT @uname = UName from UserInfo where UserID = @userid
31
32GO
方法三:一个判断登陆
1public static int VerifyPassword(string strUsername, string strPassword)
2 {
3 // IDataParameter[] parameters = helper.GetSpParameterSet(cs, "VerifyPassword");
4 IDataParameter[] parameters = new IDataParameter[3];
5 parameters[0] = helper.GetParameter("@username", strUsername);
6 parameters[1] = helper.GetParameter("@password", strPassword);
7 parameters[2] = helper.GetParameter("ReturnValue",DbType.Int16, 4, ParameterDirection.ReturnValue);
8
9 helper.ExecuteNonQuery(cs, "VerifyPassword", parameters);
10 return (int)parameters[2].Value;
11 }
12存储过程
13PROCEDURE [dbo].[VerifyPassword]
14(
15 @username Varchar( 20 ),
16 @password Varchar( 20 )
17 --@reason int OutPut
18)
19AS
20DECLARE @foundUser Varchar( 20 )
21SELECT @foundUser = ul_username
22 FROM UserList
23 WHERE ul_username = @username
24 AND ul_password = @password
25IF @foundUser IS NOT NULL
26 --set @reason =0
27return 0
28ELSE
29 IF Exists( SELECT ul_username
30 FROM UserList WHERE ul_username = @username )
31 --set @reason =2
32return 2
33 ELSE
34 --set @reason = 1
35return 1
36
37
2 {
3 // IDataParameter[] parameters = helper.GetSpParameterSet(cs, "VerifyPassword");
4 IDataParameter[] parameters = new IDataParameter[3];
5 parameters[0] = helper.GetParameter("@username", strUsername);
6 parameters[1] = helper.GetParameter("@password", strPassword);
7 parameters[2] = helper.GetParameter("ReturnValue",DbType.Int16, 4, ParameterDirection.ReturnValue);
8
9 helper.ExecuteNonQuery(cs, "VerifyPassword", parameters);
10 return (int)parameters[2].Value;
11 }
12存储过程
13PROCEDURE [dbo].[VerifyPassword]
14(
15 @username Varchar( 20 ),
16 @password Varchar( 20 )
17 --@reason int OutPut
18)
19AS
20DECLARE @foundUser Varchar( 20 )
21SELECT @foundUser = ul_username
22 FROM UserList
23 WHERE ul_username = @username
24 AND ul_password = @password
25IF @foundUser IS NOT NULL
26 --set @reason =0
27return 0
28ELSE
29 IF Exists( SELECT ul_username
30 FROM UserList WHERE ul_username = @username )
31 --set @reason =2
32return 2
33 ELSE
34 --set @reason = 1
35return 1
36
37