Hi everyone,
I keep getting the following error. What I am trying to do is just get identity from database. I tried so many ways and wasted the whole day. I have written the snippet of sp and c#.
Please someone help me
Formal parameter '@QuestionnaireDescription' was defined as OUTPUT but the actual parameter not declared OUTPUT
This is the stored procedure which gives identity as OUTPUT
Code:Create PROCEDURE InsertQuestionAndGetQuestionID @QuestionName VARCHAR(2000), @QuestionTitle VARCHAR(2000), @QuestionDescription VARCHAR(5000), @GetOutPut INT OUTPUT as --SET NOCOUNT ON DECLARE @NewQuestionID INT INSERT INTO dbo.Questions ( QuestionName, QuestionTitle, QuestionDescription ) VALUES ( @QuestionName, @QuestionTitle, @QuestionDescription ) SET @NewQuestionID = @@Identity BEGIN IF @NewQuestion > 0 BEGIN SELECT @GetOutPut = @NewQuestionID END ELSE BEGIN SELECT @GetOutPut = 0 END END and c# method which uses the above stored procedure......... public int InsertQuestionAndGetIdentity(string questionName, string questionTitle, string questionDescription) { int questionId; SqlConnection connection = this.GetConnection(); SqlCommand sqlCommand = new SqlCommand("InsertQuestionAndGetQuestionID",connection); sqlCommand.CommandType= CommandType.StoredProcedure; SqlParameter sqlInsertParameter; sqlInsertParameter = sqlCommand.Parameters.Add(new SqlParameter("@QuestionName",SqlDbType.VarChar,2000)); sqlInsertParameter.Value = questionName; sqlInsertParameter = sqlCommand.Parameters.Add(new SqlParameter("@QuestionTitle",SqlDbType.VarChar, 2000)); sqlInsertParameter.Value = questionTitle; sqlInsertParameter = sqlCommand.Parameters.Add(new SqlParameter("@QuestionDescription",SqlDbType.VarChar,5000)); sqlInsertParameter.Value = questionDescription; sqlInsertParameter.Value = sqlCommand.Parameters.Add(new SqlParameter("@GetOutPut",SqlDbType.Int)); sqlInsertParameter.Direction = ParameterDirection.Output; sqlInsertParameter.Value = 0; try { connection.Open(); sqlCommand.ExecuteNonQuery(); questionId = Convert.ToInt16(sqlInsertParameter.Value); return questionId; } catch(Exception exception) { throw exception; } finally { connection.Close(); } }




Reply With Quote