G
Guest
All,
I am writing a form field application for user data with firstname,
middlename, lastname, department. I have written an Add/Edit Stored Procedure
in SQL 2000 which checks if an ID exists, if so it backs up existing and
updates, then is supposed to return the ID back and a status ID, if it does
not exist it returns the idenentity and a status. Currently it is returning
the status, but not the newID, which is passed as an output parameter, it is
only returning a 0, but in SQL query analizer, it returns the correct value.
What am I doing wrong so I can get it to return correctly?
Here is the code for the procedure.
--------------------
ALTER PROCEDURE sp_EditAuthorization
@ID AS INTEGER,
@FIRSTNAME as VARCHAR(100),
@MIDDLENAME AS VARCHAR(100),
@LASTNAME AS VARCHAR(100),
@AUTHID AS INTEGER,
@NEWID AS INTEGER OUTPUT
AS
DECLARE @STATUS AS INTEGER
IF @ID > 0 --Begin Edit
BEGIN
SELECT @NEWID = @ID
INSERT INTO tblAuthorizationArchive (ID, FIRSTNAME, MNAME, LASTNAME,
AUTHID, MOD_DATE, CONTENT_TYPE, FILENAME, AUTH_FORM)
SELECT ID, FIRSTNAME, MNAME, LASTNAME, AUTHID, MOD_DATE,
CONTENT_TYPE, FILENAME, AUTH_FORM FROM tblAuthorizations
WHERE ID = @ID
SELECT @STATUS = @@ERROR
IF @@ERROR = 0
BEGIN
UPDATE tblAuthorizations
SET FIRSTNAME = LTRIM(RTRIM(@FIRSTNAME)), MNAME =
LTRIM(RTRIM(@MIDDLENAME)),
LASTNAME = LTRIM(RTRIM(@LASTNAME)), AUTHID = @AUTHID,
MOD_DATE = GETDATE() WHERE ID = @ID
SELECT @STATUS = @@ERROR
END
END
ELSE
BEGIN
INSERT INTO tblAuthorizations (FIRSTNAME, MNAME, LASTNAME,
AUTHID, MOD_DATE)
VALUES (LTRIM(RTRIM(@FIRSTNAME)),
LTRIM(RTRIM(@MIDDLENAME)),
LTRIM(RTRIM(@LASTNAME)), @AUTHID, GETDATE())
SELECT @NEWID = @@IDENTITY
SELECT @STATUS = @@ERROR
END
RETURN @STATUS
------------
Here is the call in VB.NET
-------------------------
Public Overrides Function AddEditAuthorization(ByVal ID As Integer,
ByVal FirstName As String, ByVal MiddleName As String, ByVal LastName As
String, ByVal AuthID As String) As Integer
Try
Dim OutID As Integer
Dim NewID As Integer
OutID = SqlHelper.ExecuteScalar(ConnectionString,
"sp_EditAuthorization", ID, FirstName, MiddleName, LastName, AuthID, NewID)
Return CStr(NewID)
Catch ex As Exception
End Try
End Function
---------------
I am not handling the return of both variables out of VB yet, since NEWID is
not returning the correct value.
Any ideas?
Thank you,
Nathan
I am writing a form field application for user data with firstname,
middlename, lastname, department. I have written an Add/Edit Stored Procedure
in SQL 2000 which checks if an ID exists, if so it backs up existing and
updates, then is supposed to return the ID back and a status ID, if it does
not exist it returns the idenentity and a status. Currently it is returning
the status, but not the newID, which is passed as an output parameter, it is
only returning a 0, but in SQL query analizer, it returns the correct value.
What am I doing wrong so I can get it to return correctly?
Here is the code for the procedure.
--------------------
ALTER PROCEDURE sp_EditAuthorization
@ID AS INTEGER,
@FIRSTNAME as VARCHAR(100),
@MIDDLENAME AS VARCHAR(100),
@LASTNAME AS VARCHAR(100),
@AUTHID AS INTEGER,
@NEWID AS INTEGER OUTPUT
AS
DECLARE @STATUS AS INTEGER
IF @ID > 0 --Begin Edit
BEGIN
SELECT @NEWID = @ID
INSERT INTO tblAuthorizationArchive (ID, FIRSTNAME, MNAME, LASTNAME,
AUTHID, MOD_DATE, CONTENT_TYPE, FILENAME, AUTH_FORM)
SELECT ID, FIRSTNAME, MNAME, LASTNAME, AUTHID, MOD_DATE,
CONTENT_TYPE, FILENAME, AUTH_FORM FROM tblAuthorizations
WHERE ID = @ID
SELECT @STATUS = @@ERROR
IF @@ERROR = 0
BEGIN
UPDATE tblAuthorizations
SET FIRSTNAME = LTRIM(RTRIM(@FIRSTNAME)), MNAME =
LTRIM(RTRIM(@MIDDLENAME)),
LASTNAME = LTRIM(RTRIM(@LASTNAME)), AUTHID = @AUTHID,
MOD_DATE = GETDATE() WHERE ID = @ID
SELECT @STATUS = @@ERROR
END
END
ELSE
BEGIN
INSERT INTO tblAuthorizations (FIRSTNAME, MNAME, LASTNAME,
AUTHID, MOD_DATE)
VALUES (LTRIM(RTRIM(@FIRSTNAME)),
LTRIM(RTRIM(@MIDDLENAME)),
LTRIM(RTRIM(@LASTNAME)), @AUTHID, GETDATE())
SELECT @NEWID = @@IDENTITY
SELECT @STATUS = @@ERROR
END
RETURN @STATUS
------------
Here is the call in VB.NET
-------------------------
Public Overrides Function AddEditAuthorization(ByVal ID As Integer,
ByVal FirstName As String, ByVal MiddleName As String, ByVal LastName As
String, ByVal AuthID As String) As Integer
Try
Dim OutID As Integer
Dim NewID As Integer
OutID = SqlHelper.ExecuteScalar(ConnectionString,
"sp_EditAuthorization", ID, FirstName, MiddleName, LastName, AuthID, NewID)
Return CStr(NewID)
Catch ex As Exception
End Try
End Function
---------------
I am not handling the return of both variables out of VB yet, since NEWID is
not returning the correct value.
Any ideas?
Thank you,
Nathan