Re: Cannot add the data into the table



On Wed, 10 Jan 2007 14:29:00 -0800, BMW wrote:

There is my code of vb.net and SQL stored procedure

(snip)
Dim par2 As New SqlParameter("@RowCount",
SqlDbType.Int)
par2.Direction = ParameterDirection.ReturnValue
cmd.Parameters.Add(par2)

Hi BMW,

You are defining a third (output) parameter here, ...

(snip)

Create PROCEDURE [dbo].[spDataTest]

-- Add the parameters for the stored procedure here

@Subject varchar(50),
@Result nvarchar(100)

.... but the stored procedure has only two parameters, ...

(snip)

return @@rowcount

.... and the rowcount is returned as a return value, not as an output
parameter.

You can fix this by changing the stored procedure as follows:

CREATE PROCEDURE dbo.spDataTest
@Subject varchar(50),
@Result nvarchar(100),
@RowCount int OUTPUT
AS
SET NOCOUNT ON;

INSERT INTO dbo.Result (Subject, Result)
VALUES (@Subject, @Result);

SET @RowCount = @@ROWCOUNT;

--
Hugo Kornelis, SQL Server MVP
My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
.



Relevant Pages

  • Re: Can @@ROWCOUNT return NULL?
    ... from the stored procedure. ... > Immediately after each statement I save the value returned by @@ROWCOUNT to ... it appears that in SQL Server ... This is not the case here - the only DML queries are INSERTs into ...
    (comp.databases.ms-sqlserver)
  • Can @@ROWCOUNT return NULL?
    ... I am troubleshooting a relatively large stored procedure with ... Immediately after each statement I save the value returned by @@ROWCOUNT to ... Before doing any further troubleshooting, I would like to rule out the ... it appears that in SQL Server ...
    (comp.databases.ms-sqlserver)
  • Re: Stored procedure question
    ... comparison(in case u haven't configured you sql server) ... > You could capture the rowcount after this, ... > Vyas, MVP ... > I need to write a stored procedure which changes user password based on ...
    (microsoft.public.sqlserver.programming)
  • Re: Can @@ROWCOUNT return NULL?
    ... I am troubleshooting a relatively large stored procedure with ... > Immediately after each statement I save the value returned by @@ROWCOUNT ... > Before doing any further troubleshooting, I would like to rule out the ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ...
    (comp.databases.ms-sqlserver)
  • Re: Stored procedure question
    ... Thank you Narayana ... > You could capture the rowcount after this, ... > I need to write a stored procedure which changes user password based on ... > validity of his old password. ...
    (microsoft.public.sqlserver.programming)