SubSonic的存储过程操作

一个不甚完善的存储过程:

-----------------------------------存储过程代码开始------------------------------------

-- ================================================
-- 作用是代替自动增长型的ID,这样便于分表的维护
-- ================================================

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

ALTER PROCEDURE [dbo].[GenerateRUID]

@tblName varchar(50),
@currentnumber int OUTPUT

AS
SET NOCOUNT ON
Declare @tempnumber int

Begin

SELECT @tempnumber= CurrentNumber
FROM Ruid
WHERE (TableName = @tblName)

SET @tempnumber=@tempnumber+1
  
Update Ruid
SET CurrentNumber=@tempnumber
Where TableName=@tblName

SET @currentnumber=@tempnumber
END

-----------------------------------存储过程代码结束------------------------------------

以下是利用SubSonic2.0使用该存储过程的代码:

-----------------------------------代码开始------------------------------------

public static int GetRUID(string tblName)
        {
            StoredProcedure spd = new StoredProcedure("GenerateRUID");
            spd.Command.AddParameter("@tblName", tblName);
            spd.Command.AddOutputParameter("@currentnumber");
            spd.Execute();
            int currentnumber = int.Parse(spd.OutputValues[0].ToString());
            return currentnumber;
        }

-----------------------------------代码结束------------------------------------

posted @ 2010-03-17 22:48  kingkoo  阅读(1159)  评论(1编辑  收藏  举报