Hi all,
I have a stored procedure that I would like to have return the created autoid (this is the primary key field, an integer and an identity with an autoincrement of 1). However, when I run the following code I receive the following errors:
Error 9
Description: An SQLParameter with ParameterName '@Error'
is not contained by this SQLParameterCollection.
and
Error 5
Description: Procedure 'sp_NewLeaveSlip' expects parameter
@LeaveID, which is not supplied.
Here is the stored procedure:
HERE is my code calling the stored procedure:
Any help would be greatly appreciated!
Thanks,
jbehrne
If at first you don't succeed, call in an airstrike. - Murphy's Laws of Combat Operations
I have a stored procedure that I would like to have return the created autoid (this is the primary key field, an integer and an identity with an autoincrement of 1). However, when I run the following code I receive the following errors:
Error 9
Description: An SQLParameter with ParameterName '@Error'
is not contained by this SQLParameterCollection.
and
Error 5
Description: Procedure 'sp_NewLeaveSlip' expects parameter
@LeaveID, which is not supplied.
Here is the stored procedure:
Code:
CREATE PROCEDURE dbo.sp_NewLeaveSlip(
@LeaveID int OUTPUT,
@EID varchar(10),
@DateInput datetime,
@StartD datetime,
@StartT datetime,
@EndT datetime,
@EndD datetime,
@Hours decimal(18,2),
@LeaveT varchar(50),
@Comments varchar(200),
@FMLASelected bit,
@FMLAReason varchar(100),
@Name varchar(75) )
AS INSERT INTO dbo.LeaveSlips
(EmployeeID, DateLeaveInput, StartDate, StartTime, EndTime, EndDate, HoursRequested, LeaveType, Remarks, FMLA, FMLAReason,
EmployeeName)
VALUES (@EID, @DateInput, @StartD, @StartT, @EndT, @EndD, @Hours, @LeaveT, @Comments, @FMLASelected, @FMLAReason, @Name)
SET @LeaveID = @@IDENTITY
RETURN @@ERROR
GO
HERE is my code calling the stored procedure:
Code:
Dim sCmd = New SqlCommand("sp_NewLeaveSlip", cnSql)
sCmd.CommandType = CommandType.StoredProcedure
Try
With sCmd.Parameters
.Add("@EID", SqlDbType.VarChar).Value = IdNumber
.Add("@DateInput", SqlDbType.DateTime).Value = Today()
.Add("@StartD", SqlDbType.DateTime).Value = Me.txtStartDate.Text
.Add("@StartT", SqlDbType.DateTime).Value = Me.txtStartTm.Text
.Add("@EndT", SqlDbType.DateTime).Value = Me.txtEndTm.Text
.Add("@EndD", SqlDbType.DateTime).Value = Me.txtEndDate.Text
.Add("@Hours", SqlDbType.Decimal).Value = Me.txtHoursRequested.Text
.Add("@LeaveT", SqlDbType.VarChar).Value = Me.cmbLeaveType.Text
.Add("@Comments", SqlDbType.VarChar).Value = Me.txtComment.Text
.Add("@FMLASelected", SqlDbType.Bit).Value = Me.chkFMLA.CheckState
.Add("@FMLAReason", SqlDbType.VarChar).Value = Me.cmbFMLAReason.Text
.Add("@Name", SqlDbType.VarChar).Value = Me.cmbEmployeeName.Text
End With
sCmd.Parameters("@Error").Direction = ParameterDirection.ReturnValue
sCmd.Parameters("@LeaveID").Direction = ParameterDirection.Output
Catch ex As Exception
MsgBox("Error: " & Err.Number & "Description: " & Err.Description)
End Try
sCmd.ExecuteNonQuery()
If sCmd.Parameters("@Error").Value = 0 Then
SelectedLeaveID = sCmd.Parameters("@LeaveID").Value
CanPrint = True
Else
CanPrint = False
MsgBox("An uknown error has occurred." & vbCrLf & "Please record this information and contact your computer analyst immediately!" & vbCrLf & vbCrLf & "Error: " & Err.Number & vbCrLf & "Description: " & Err.Description, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "Error"))
Exit Function
End If
Any help would be greatly appreciated!
Thanks,
jbehrne
If at first you don't succeed, call in an airstrike. - Murphy's Laws of Combat Operations