CREATE PROCEDURE [dbo].[MyWorkLog_JudgUserLogin]
@isExist as int output, -- 输入出结果
@userName nvarchar(20), -- 用户名称
@passWord nvarchar(20) -- 用户密码
AS
BEGIN
SET @isExist = (SELECT COUNT(*) FROM [Login] WHERE userName = @userName AND Password = @passWord)
END
/// <summary>
/// 判断用户是否存在
/// </summary>
/// <param name="userName">用户名</param>
/// <param name="Password">密码</param>
/// <returns></returns>
public int userLoginOperator(string userName, string Password)
{
SqlCommand cmd = this.GetSqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "MyWorkLog_JudgUserLogin";//存储过程的名称
SqlParameter TheParameter;
//用户名
TheParameter = cmd.Parameters.Add("@userName", SqlDbType.NVarChar);
TheParameter.Direction = ParameterDirection.Input;
TheParameter.Value = userName;
//密码
TheParameter = cmd.Parameters.Add("@passWord", SqlDbType.NVarChar);
TheParameter.Direction = ParameterDirection.Input;
TheParameter.Value = Password;
//ID号
TheParameter = cmd.Parameters.Add("@isExist", SqlDbType.Int);
cmd.Parameters["@isExist"].Direction = ParameterDirection.Output;
cmd.ExecuteNonQuery();
int isExist = Convert.ToInt32(cmd.Parameters["@isExist"].Value.ToString());
return isExist;//返回一个数
}
@isExist as int output, -- 输入出结果
@userName nvarchar(20), -- 用户名称
@passWord nvarchar(20) -- 用户密码
AS
BEGIN
SET @isExist = (SELECT COUNT(*) FROM [Login] WHERE userName = @userName AND Password = @passWord)
END
/// <summary>
/// 判断用户是否存在
/// </summary>
/// <param name="userName">用户名</param>
/// <param name="Password">密码</param>
/// <returns></returns>
public int userLoginOperator(string userName, string Password)
{
SqlCommand cmd = this.GetSqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "MyWorkLog_JudgUserLogin";//存储过程的名称
SqlParameter TheParameter;
//用户名
TheParameter = cmd.Parameters.Add("@userName", SqlDbType.NVarChar);
TheParameter.Direction = ParameterDirection.Input;
TheParameter.Value = userName;
//密码
TheParameter = cmd.Parameters.Add("@passWord", SqlDbType.NVarChar);
TheParameter.Direction = ParameterDirection.Input;
TheParameter.Value = Password;
//ID号
TheParameter = cmd.Parameters.Add("@isExist", SqlDbType.Int);
cmd.Parameters["@isExist"].Direction = ParameterDirection.Output;
cmd.ExecuteNonQuery();
int isExist = Convert.ToInt32(cmd.Parameters["@isExist"].Value.ToString());
return isExist;//返回一个数
}
首先在数据里创建一张用户表(login),再创建一个存储过程,其传入两个值,输入一个值,对出输出来的那个值进行判断。