我有一个如下所示的存储过程..
CREATE PROCEDURE [dbo].[spMYSPDetails]
@Id VarChar(6),
@Name VarChar(50),
@Limit Money,
@Status VarChar(1),
@Accounts As SmallInt
AS BEGIN
IF(LEN(ISNULL(@strDebtorId, '')) = 0) BEGIN
WHILE 0 = 0 BEGIN
SET @Id = '9' + dbo.fnGenerateRandomCode(5, '0123456789')
IF NOT EXISTS (SELECT 1 FROM mytbl WITH (NOLOCK) WHERE s_Id = @Id) BEGIN
INSERT INTO Mytbl
(D_Id,
D_Name,
D_Limit,
D_Status,
D_Accounts,
D_dtmStamp,
D_Balance)
VALUES
(@Id,
@Name,
@Limit,
@Status,
@Accounts,
GETDATE(),
@Limit)
BREAK
END
我有 c# 清晰的代码可以像这样调用这个 SP...
try
{
string Id = "";
if (hdDId.Value.ToString() != "")
{
Id = hdDId.Value.ToString();
}
objDB.blnParamClear();
objDB.blnParamAdd(ParameterDirection.Input, "@Id", SqlDbType.VarChar, 6, Id.ToString());
objDB.blnParamAdd(ParameterDirection.Input, "@Name", SqlDbType.VarChar, 50, txtName.Value.ToString());
objDB.blnParamAdd(ParameterDirection.Input, "@Limit", SqlDbType.Money, 8, decimal.Parse(txtLimit.Value.ToString()));
objDB.blnParamAdd(ParameterDirection.Input, "@Status", SqlDbType.VarChar, 1, cboStatus.Value);
objDB.blnParamAdd(ParameterDirection.Input, "@intMaxAccounts", SqlDbType.SmallInt, 4, txtAccnts.Value.ToString());
blnResult = (objDB.lngExecuteSP("spMYSPDetails") == 0);
}
现在我想在 C# 中捕获自动生成的(随机)ID 以供参考。我试过但无法捕捉..有什么方法可以捕捉到由 SQL 中的 SP 生成的相同 ID。给我一些建议......