|
-
Jul 15th, 2005, 12:29 PM
#1
Thread Starter
Member
Weird Error Message in dot net
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();
}
}
Last edited by Hack; Jul 18th, 2005 at 10:23 AM.
***learning everyday ***
-
Jul 20th, 2005, 08:58 AM
#2
Re: Weird Error Message in dot net
Code:
@QuestionDescription VARCHAR(5000) OUTPUT,
Does that fix it?
I don't live here any more.
-
Jul 21st, 2005, 02:51 AM
#3
Re: Weird Error Message in dot net
Shouldn't the SP contain a line that says
RETURN @GetOutPut
?
-
Jul 21st, 2005, 12:34 PM
#4
Re: Weird Error Message in dot net
Look closely at this line 
Code:
sqlInsertParameter.Value = sqlCommand.Parameters.Add(new SqlParameter("@GetOutPut",SqlDbType.Int));
[Edit]
Apparently can't embolden code sections now...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|