国产探花免费观看_亚洲丰满少妇自慰呻吟_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語句所作的判斷數和字段數基本上是一致的,這里會給入參賦初始值,如果不等于初始值就說明數據層類有傳遞參數進來,這樣就加上相應條件字符的查詢條件。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 抚顺县| 沧源| 南宁市| 宁波市| 江孜县| 鄂托克旗| 会同县| 宁津县| 永川市| 固镇县| 大竹县| 梁河县| 凯里市| 驻马店市| 鲜城| 吕梁市| 会宁县| 页游| 常宁市| 遂昌县| 会理县| 凌海市| 枝江市| 英德市| 前郭尔| 黄浦区| 兴文县| 南投市| 建瓯市| 浙江省| 宜君县| 昌吉市| 黄大仙区| 九龙县| 张家口市| 曲沃县| 桦川县| 普兰县| 泗阳县| 宁陵县| 泾川县|