【发布时间】:2015-08-26 12:15:37
【问题描述】:
我已经让这个 SP 来检查用户是否拥有存储在不同表中的任何许可证..
我将结果放入数据集中,并从该数据集中获得带有计数的单个结果,如果计数大于零,则该用户拥有许可证。
这是SP
ALTER PROCEDURE [dbo].[UserCheck]
(
@activatedBy varchar(30),
@brand varchar(20)
)
AS
BEGIN
DECLARE @acctId as BIGINT
SELECT @acctId = pk_acct_id from accounts with(nolock) where email = @activatedBy and brand = @brand
IF LEN(@acctId) > 1
BEGIN
SELECT count(*) from dbo.links with(nolock) where one = @acctId
union all
SELECT COUNT(*)FROM waveactivationinfo with(nolock) where Activated_by = @acctId
union all
SELECT COUNT(*) FROM ABCActivationInfo with(nolock) WHERE Activated_by = @acctId
union all
SELECT COUNT(*) FROM CSE_ActivationInfo with(nolock) WHERE activated_by = @acctId
union all
SELECT COUNT(*) FROM Connect_ActivationInfo with(nolock) WHERE activated_by = @acctId
union all
SELECT COUNT(*) FROM LicActivationInfo with(nolock) WHERE Activated_by = @acctId
END
END
GO
然后在 DAL 中,我将结果捕获到这样的数据集中
public DataSet UserCheck(string strEmailID, string strBrand)
{
DataSet ds = new DataSet();
List<SqlParameter> ParaList = new List<SqlParameter>();
ParaList.Add(new SqlParameter("@activatedBy", strEmailID));
ParaList.Add(new SqlParameter("@brand", strBrand));
ds = SqlHelper.ExecuteDataset(new SqlConnection(ConfigurationManager.ConnectionStrings["DB"].ConnectionString), CommandType.StoredProcedure, "UserCheck", Convert.ToInt32(Utility.GetConfigValue("Connection_TimeOut")), ParaList.ToArray());
return ds;
}
我正在像这样在后面的代码中检索该数据集...
DataSet ds = userDeactivate.UserCheck(txtEmailID.Text.Trim(), brandType);
if (ds != null)
{
if (ds.Tables[0].Rows.Count > 0)
{
osCount = Int32.Parse(ds.Tables[0].Rows[0].ItemArray[0].ToString());
waveCount=Int32.Parse(ds.Tables[0].Rows[1].ItemArray[0].ToString());
aCount = Int32.Parse(ds.Tables[0].Rows[2].ItemArray[0].ToString());
PassCount = Int32.Parse(ds.Tables[0].Rows[3].ItemArray[0].ToString());
quickCount = Int32.Parse(ds.Tables[0].Rows[4].ItemArray[0].ToString());
vmcCount = Int32.Parse(ds.Tables[0].Rows[5].ItemArray[0].ToString());
}
}
我认为这不是检查用户是否拥有许可证的好方法.. 有没有其他选择
有什么方法可以简单地从 SP 为每个结果集返回代码.. 如果我想从所有查询中获取所有计数,我是否需要修改 DAL 中的任何代码...
【问题讨论】:
-
在您的存储过程输出参数中使用 hasLicensce 并更改为 SET has_license = EXISTS(SELECT 1 from dbo.links with(nolock) where one = acctId ...) 并在最后返回输出。跨度>
-
您的应用程序中是否需要这些多重计数(*),还是只是简单的 INFO hasLicense?
-
我还需要个人计数,因为我需要向客户展示...
标签: sql sql-server sql-server-2008 sql-server-2005