SqlParameter 的使用

SqlParameter[] sqlParams = new SqlParameter[2];
sqlParams[0] = new SqlParameter("@RoleId", roleName);
sqlParams[1] = new SqlParameter("@Deleted", false) { DbType = System.Data.DbType.Boolean };
 var q = Context.Database.SqlQuery<UserInfo>("exec GetUsersByRoleID @RoleId,@Deleted", sqlParams);
return q.ToListAsync();

 

USE [OLsuitedb]

GO

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO  

ALTER PROCEDURE  [dbo].[GetSiteTracks]  

 (     

@ShortUrl nvarchar(max)

)

AS   

BEGIN  

DECLARE @wheres nvarchar(max)

 set @wheres=' where 1=1 '  

if @ShortUrl != ''  begin    

set @wheres += ' and ShortUrl = @ShortUrl'    

end

 declare @sql nvarchar(max)  

   set @sql = N'select Source,COUNT(Source) as NumCount from SiteTracks'+ @wheres+' group by Source'  

   print @sql  

exec sp_executesql @sql,N'@ShortUrl nvarchar(max)',@ShortUrl

END

posted @ 2017-12-11 09:20  李寒星  阅读(2107)  评论(0编辑  收藏  举报