国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

Asp.Net(C#)+Sql Server三層架構下數據存取方案(二)

2024-07-10 12:57:50
字體:
來源:轉載
供稿:網友
存儲過程:

/**********************************

功能:根據一定條件讀取功能記錄

作者:rexsp

創建日期:2004-01-13

修改者:

修改日期:

**********************************/

alter procedure getscoresetting

(

@scoresettingid int=-1, ---設置id

@functionid int=-1, ---功能id

@operationid int=-1, ---操作id

@roletypeid int=-1, ---角色類型

@bbstypeid int=-1, ---版塊類型

@score int=-1, ---積分設置

@bb int=-1, ---幣幣設置

@buytype int=-1, ---購買類型 0:不是購買類型 1:一次性購買 2:反復購買

@functionstate int=-1 ---功能狀態

)

as

set nocount on

declare @strsql nvarchar(1000)

set @strsql = 'select * from [scoresetting] where @ckscoresettingid = @ckscoresettingid'

--- add keywords begin ---

if @scoresettingid<> -1

begin

set @strsql = @strsql + ' and scoresettingid= @ckscoresettingid'

end

if @functionid<> -1

begin

set @strsql = @strsql + ' and functionid= @ckfunctionid'

end

if @operationid<>-1

begin

set @strsql = @strsql + ' and operationid = @ckoperationid'

end

if @roletypeid<>-1

begin

set @strsql = @strsql + ' and roletypeid = @ckroletypeid'

end

if @bbstypeid<>-1

begin

set @strsql = @strsql + ' and bbstypeid = @ckbbstypeid'

end

if @score<>-1

begin

set @strsql = @strsql + ' and score = @ckscore'

end

if @bb<>-1

begin

set @strsql = @strsql + ' and bb= @ckbb'

end

if @buytype<>-1

begin

set @strsql = @strsql + ' and buytype= @ckbuytype'

end

if @functionstate<>-1

begin

set @strsql = @strsql + ' and functionstate= @ckfunctionstate'

end

--- add where key word ---

--- run sql begin ---

execute sp_executesql @strsql,

n' @ckscoresettingid int,

@ckfunctionid int,

@ckoperationid int,

@ckroletypeid int,

@ckbbstypeid int,

@ckscore int,

@ckbb int,

@ckbuytype int,

@ckfunctionstate int',

@[email protected],

@[email protected],

@ckoperationid = @operationid,

@ckroletypeid = @roletypeid,

@ckbbstypeid = @bbstypeid,

@ckscore = @score,

@ckbb = @bb,

@ckbuytype = @buytype,

@ckfunctionstate = @functionstate

--- run sql end ---



一點說明:

此存儲過程會根據數據層的類有沒有傳遞相應的參數值進來而動態創建查詢語句,然后用系統自帶的存儲過程執行sql語句,用系統存儲過程執行sql語句的好處是可以自動轉義字符。而動態創建查詢語句的好處,就非常大了,這會省下我們寫很多種條件判斷,尤其是對那些字段比較多的表來講,一個排列組合下來的情況太多了,而利用存儲過程動態創建sql語句所作的判斷數和字段數基本上是一致的,這里會給入參賦初始值,如果不等于初始值就說明數據層類有傳遞參數進來,這樣就加上相應條件字符的查詢條件。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 仲巴县| 洮南市| 慈溪市| 华蓥市| 天津市| 贺兰县| 海门市| 呼和浩特市| 巴楚县| 中超| 宣威市| 长沙县| 通渭县| 宝山区| 祁东县| 阳朔县| 孟连| 临西县| 墨玉县| 英德市| 开鲁县| 金沙县| 焦作市| 区。| 深泽县| 青田县| 昌乐县| 修水县| 郸城县| 晋中市| 台安县| 永和县| 武清区| 永昌县| 湄潭县| 米易县| 镇平县| 德江县| 昌都县| 辛集市| 石景山区|