一个不甚完善的存储过程:
———————————–存储过程代码开始————————————
— ================================================
— 作用是代替自动增长型的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;
}
———————————–代码结束————————————
引用:http://www.sim-zone.cn/?uid-6-action-viewspace-itemid-548