登陆时得到用户权限,但一直提示说“未将对象引用设置到对象的实例。”
检查了好几遍都没发现哪里有问题:
ALTER PROCEDURE dbo.Pr_GetUserPower
/*
获取用户权限
*/
@usercode varchar(20),
@module varchar(1000) OUTPUTAS
DECLARE @temp varchar(50)
SET @temp = (SELECT usermodule FROM ts_userpopedom WHERE usercode = @usercode)
IF (@temp = '系统管理员')
BEGIN
SELECT @module = module FROM ts_usermodule WHERE usermodule = '系统管理员'
END
ELSE
BEGIN
SELECT @module = module FROM ts_userpopedom WHERE usercode = @usercode
END
public string GetPower(string sCode)
{
SqlParameter[] prams = {
db.MakeInParam("@usercode",SqlDbType.VarChar,20,sCode),
db.CreateOutParam("@module",SqlDbType.VarChar,1000)
};
db.RunProc("Pr_GetUserPower",prams);
string sPower = prams[1].Value.ToString();
return sPower;
}
//这里就提示出错
Response.Cookies["UserPower"].Value = user.GetPower(this.txtUserName.Text);
麻烦各位看看问题出在哪里
谢谢!~
检查了好几遍都没发现哪里有问题:
ALTER PROCEDURE dbo.Pr_GetUserPower
/*
获取用户权限
*/
@usercode varchar(20),
@module varchar(1000) OUTPUTAS
DECLARE @temp varchar(50)
SET @temp = (SELECT usermodule FROM ts_userpopedom WHERE usercode = @usercode)
IF (@temp = '系统管理员')
BEGIN
SELECT @module = module FROM ts_usermodule WHERE usermodule = '系统管理员'
END
ELSE
BEGIN
SELECT @module = module FROM ts_userpopedom WHERE usercode = @usercode
END
public string GetPower(string sCode)
{
SqlParameter[] prams = {
db.MakeInParam("@usercode",SqlDbType.VarChar,20,sCode),
db.CreateOutParam("@module",SqlDbType.VarChar,1000)
};
db.RunProc("Pr_GetUserPower",prams);
string sPower = prams[1].Value.ToString();
return sPower;
}
//这里就提示出错
Response.Cookies["UserPower"].Value = user.GetPower(this.txtUserName.Text);
麻烦各位看看问题出在哪里
谢谢!~
提示出错的行数就是这句“ db.RunProc("Pr_GetUserPower",prams);”
SELECT @module =(select module FROM ts_userpopedom WHERE usercode = @usercode)
你可以单独运行以下存储过程,判断是否是存储过程的错误。
一般是程序的错,你这样写试试,如果过了就是你程序 Response.Cookies["UserPower"].Value的值有问题
if(Response.Cookies["UserPower"] != null)
{
Response.Cookies["UserPower"].Value = user.GetPower(this.txtUserName.Text);
}
SET @temp = (SELECT usermodule FROM ts_userpopedom WHERE usercode = @usercode)
IF (@temp = '系统管理员')
BEGIN
SELECT @module = module FROM ts_usermodule WHERE usermodule = '系统管理员'
END
ELSE
BEGIN
SELECT @module = module FROM ts_userpopedom WHERE usercode = @usercode
END存储 过程这边SET @temp = (SELECT usermodule FROM ts_userpopedom WHERE usercode = @usercode)
判断一下有没有值
if exists(SELECT usermodule FROM ts_userpopedom WHERE usercode = @usercode)
SET @temp = (SELECT usermodule FROM ts_userpopedom WHERE usercode = @usercode)