日期:2014-05-19  浏览次数:20459 次

重写SqlMembershipProvider的CreateUser方法,帮我看看这个查询语句
我想要在客户注册后自动加入一个我指定的用户组,所以重写了CreateUser,加入用户组的代码如下:
StringBuilder   sb   =   new   StringBuilder();
sb.Append( "DECLARE   @RoleId   UniqueIdentifier; ");
sb.Append( "DECLARE   @UserId   UniqueIdentifier; ");
sb.Append( "SELECT   @RoleId=RoleId   FROM   aspnet_Roles   WHERE   LoweredRoleName=LOWER(@RoleName); ");
sb.Append( "SELECT   @UserId=UserId   FROM   aspnet_Users   WHERE   LoweredUserName=LOWER(@UserName); ");
sb.Append( "IF   @RoleId   IS   NOT   NULL   AND   @UserId   IS   NOT   NULL   ");
sb.Append( "INSERT   INTO   aspnet_UsersInRoles(UserId,RoleId)   VALUES(@UserId,@RoleId) ");

command.CommandText   =   sb.ToString();
command.Parameters.Add( "@UserName ",   SqlDbType.NVarChar,   256).Value   =   username;
command.Parameters.Add( "@RoleName ",   SqlDbType.NVarChar,   256).Value   =   this.DefaultUserRole;

command.ExecuteNonQuery();

执行完后aspnet_UsersInRoles表没有变化,是不是我的sql语句有问题?

------解决方案--------------------
为什么不调试一下看看呢?就知道sql那里写错了阿