To capture a RETURN VALUE (returned by SQL using the RETURN({number}) syntax) use:
cmdHeader.Parameters.Add("@ReturnValue", SqlDbType.Int, 4).Direction = ParameterDirection.ReturnValue;
Also, you should probably be using SCOPE_IDENTITY() instead of @@IDENTITY
Edit:
So your sproc would do something like:
DECLARE @NewId INTEGER
INSERT SomeTable(FieldA) VALUES ('Something')
SELECT @NewId = SCOPE_IDENTITY()
RETURN (@NewId)
And your C# code to retrieve that value would be:
int newId = cmdHeader.Parameters[@ReturnValue].value;
Edit 2:
Ok, the original question confused the issue as the "return value" is a different thing to what you're actually doing which is returning a single column resultset.
So, instead DON'T add a ReturnValue parameter at all. Just use ExecuteScalar() using your original SqlCommand setup as below:
int newId = Convert.ToInt32(cmdHeader.ExecuteScalar());
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…