本文介绍了如何在我的C#代码中将@NEXT_ID分配给int变量.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
CREATE PROC GETNEXTID @OPERATION VARCHAR (10)
AS
BEGIN
DECLARE @NEXT_ID INT
IF @OPERATION='USERID'
BEGIN
SELECT @NEXT_ID= ISNULL(COUNT(USER_ID),0)+1 FROM USER_DETAILS
END
ELSE IF @OPERATION='FILEID'
BEGIN
SELECT @NEXT_ID= ISNULL(COUNT(FILE_ID),0)+1 FROM FILE_DETAILS
END
ELSE IF @OPERATION='LOGID'
BEGIN
SELECT @NEXT_ID= ISNULL(COUNT(LOG_ID),0)+1 FROM LOG_OPERATION
END
ELSE IF @OPERATION='FAMILYID'
BEGIN
SELECT @NEXT_ID=ISNULL(COUNT(FAMILY_ID),0)+1 FROM FAMILY_DETAILS
END
RETURN @NEXT_ID
END
推荐答案
SqlCommand cmd = new SqlCommand("GETNEXTID",conn);
cmd.CommandType = CommandType.StoredProcedure;
conn.Open();
object next_id = cmd.ExecuteScalar(); //Cast to your desired type. E.g. int
conn.Close();
希望对您有所帮助.
Hope it helps.
这篇关于如何在我的C#代码中将@NEXT_ID分配给int变量.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!