62,254
社区成员
发帖
与我相关
我的任务
分享/// <summary>
/// 判断添加的角色名称是否重复
/// </summary>
/// <param name="name">角色名称</param>
/// <returns></returns>
public bool Exist(string name)
{
AdoHelper helper = AdoHelper.CreateHelper();
string strsql = "select count(*) from t_role where name='"+name+"'";
int i =int.Parse( helper.ExecuteScalar(strsql).ToString());
if (i > 0)
{
return true;
}
else
{
return false;
}
}CREATE PROCEDURE RegPro
@Uname varchar(20),@Pwd varchar(30),@IsInclude int output
AS
if(exists(select * from [user] Where UserName=@Uname))
set @IsInclude = 0 --存在
else
begin
set @IsInclude = 1 --不存在
insert into [user](UserName,[PassWord])values(@Uname,@Pwd)
end
GO
conn.Open();
SqlCommand comm = new SqlCommand("RegPro", conn);
comm.CommandType = CommandType.StoredProcedure;//声明为存储过程
//声明并添加参数
SqlParameter UserName = new SqlParameter("@Uname", SqlDbType.VarChar);
SqlParameter PassWord = new SqlParameter("@Pwd", SqlDbType.VarChar);
SqlParameter IsInclude = new SqlParameter("@IsInclude", SqlDbType.Int);
UserName.Value = TextBox1.Text;
PassWord.Value = TextBox2.Text;
comm.Parameters.Add(UserName);
comm.Parameters.Add(PassWord);
comm.Parameters.Add(IsInclude);
//声明为出参
IsInclude.Direction = ParameterDirection.Output;
comm.ExecuteNonQuery();
if (int.Parse(IsInclude.Value.ToString()) == 0)
{
Response.Write("已经存在此用户!");
}
else
{
Response.Write("注册成功!");
}
conn.Close();
CREATE PROCEDURE [DBO].[InsertTest]
@UserName varchar(20),
@IsHave int output
AS
if exists(Select ID From tb Where UserName = @UserName)
set @IsHave = 0 --存在
else
。。。
Go