P
Phenom
I am trying to execute a stored procedure with an output parameter. I
believe I am missing a piece of code, because the execution fails. I
don't know why. When I run the proc in query analyzer it works fine, so
I don't believe it is the procedure itself, simply something I am
missing in creating the params and executing.
I appreciate any help I can get.
Thanks.
Here is the code:
If (Page.IsValid) Then
sqlChange.CommandType = CommandType.StoredProcedure
sqlChange.CommandText = "sp01_InsertChange"
sqlChange.Parameters.Add("@it_emp_resp_id", SqlDbType.Int)
sqlChange.Parameters.Add("@emp_requestor",
SqlDbType.VarChar, 50)
sqlChange.Parameters.Add("@obj_affected_id", SqlDbType.Int)
sqlChange.Parameters.Add("@subject", SqlDbType.VarChar,
8000)
sqlChange.Parameters.Add("@reason", SqlDbType.VarChar,
8000)
sqlChange.Parameters.Add("@priority", SqlDbType.Char, 2)
sqlChange.Parameters.Add("@comments", SqlDbType.VarChar,
8000)
sqlChange.Parameters.Add("@service_interupt",
SqlDbType.Char, 2)
sqlChange.Parameters.Add("@dt_implement_sched",
SqlDbType.DateTime)
sqlChange.Parameters.Add("@dt_implement_act",
SqlDbType.DateTime)
sqlChange.Parameters.Add("@interupt_time",
SqlDbType.Decimal, 18)
sqlChange.Parameters.Add("@event_id", SqlDbType.Int)
sqlChange.Parameters("@emp_requestor").Value =
ddlAssigned.SelectedValue
sqlChange.Parameters("@emp_requestor").Value =
txtRequestor.Text
sqlChange.Parameters("@obj_affected_id").Value =
ddlAffected.SelectedValue
sqlChange.Parameters("@subject").Value = txtSubject.Text
sqlChange.Parameters("@reason").Value = txtReason.Text
sqlChange.Parameters("@priority").Value =
ddlPriority.SelectedValue
sqlChange.Parameters("@comments").Value = txtNotes.Text
sqlChange.Parameters("@service_interupt").Value =
rdBtnInterrupt.SelectedValue
sqlChange.Parameters("@dt_implement_sched").Value =
txtSchedImplement.Text
sqlChange.Parameters("@dt_implement_sched").Value =
txtActualImplement.Text
sqlChange.Parameters("@interupt_time").Value =
txtInterruptMin.Text
sqlChange.Connection = cnnChange
cnnChange.Open()
Try
sqlChange.ExecuteNonQuery()
lblSuccess.Visible = True
btnSuccess.Visible = True
Catch ex As Exception
lblFail.Visible = True
btnFail.Visible = True
lbTest.Text = sqlChange.CommandText
Finally
cnnChange.Close()
End Try
End If
Here is the stored proc code:
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE procedure sp01_InsertChange
--items inserted into tbl01_event
@it_emp_resp_id int,
@emp_requestor varchar(50),
@obj_affected_id int,
@subject varchar(8000),
@reason varchar(8000) = 'Null',
@priority char(2) = 'Null',
@comments varchar(8000) = 'Null',
@service_interupt char(2),
@dt_implement_sched datetime,
@dt_implement_act datetime,
@interupt_time decimal(18) = 'Null',
--items inserted into tbl04_doc_created
@event_id int output --generated from insert into tbl01_event
as
begin
--tbl01_event insert
insert into
tbl01_event(it_emp_resp_id,emp_requestor,dt_event,obj_affected_id,subject,
reason,
priority,comments,service_interupt,dt_implement_sched,dt_implement_act,
interupt_time,dt_created,dt_modified)
values(@it_emp_resp_id,@emp_requestor,getdate(),@obj_affected_id,@subject,
@reason,
@priority,@comments,@service_interupt,@dt_implement_sched,@dt_implement_act,
@interupt_time,getdate(),getdate())
select @event_id = @@identity
end
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
believe I am missing a piece of code, because the execution fails. I
don't know why. When I run the proc in query analyzer it works fine, so
I don't believe it is the procedure itself, simply something I am
missing in creating the params and executing.
I appreciate any help I can get.
Thanks.
Here is the code:
If (Page.IsValid) Then
sqlChange.CommandType = CommandType.StoredProcedure
sqlChange.CommandText = "sp01_InsertChange"
sqlChange.Parameters.Add("@it_emp_resp_id", SqlDbType.Int)
sqlChange.Parameters.Add("@emp_requestor",
SqlDbType.VarChar, 50)
sqlChange.Parameters.Add("@obj_affected_id", SqlDbType.Int)
sqlChange.Parameters.Add("@subject", SqlDbType.VarChar,
8000)
sqlChange.Parameters.Add("@reason", SqlDbType.VarChar,
8000)
sqlChange.Parameters.Add("@priority", SqlDbType.Char, 2)
sqlChange.Parameters.Add("@comments", SqlDbType.VarChar,
8000)
sqlChange.Parameters.Add("@service_interupt",
SqlDbType.Char, 2)
sqlChange.Parameters.Add("@dt_implement_sched",
SqlDbType.DateTime)
sqlChange.Parameters.Add("@dt_implement_act",
SqlDbType.DateTime)
sqlChange.Parameters.Add("@interupt_time",
SqlDbType.Decimal, 18)
sqlChange.Parameters.Add("@event_id", SqlDbType.Int)
sqlChange.Parameters("@emp_requestor").Value =
ddlAssigned.SelectedValue
sqlChange.Parameters("@emp_requestor").Value =
txtRequestor.Text
sqlChange.Parameters("@obj_affected_id").Value =
ddlAffected.SelectedValue
sqlChange.Parameters("@subject").Value = txtSubject.Text
sqlChange.Parameters("@reason").Value = txtReason.Text
sqlChange.Parameters("@priority").Value =
ddlPriority.SelectedValue
sqlChange.Parameters("@comments").Value = txtNotes.Text
sqlChange.Parameters("@service_interupt").Value =
rdBtnInterrupt.SelectedValue
sqlChange.Parameters("@dt_implement_sched").Value =
txtSchedImplement.Text
sqlChange.Parameters("@dt_implement_sched").Value =
txtActualImplement.Text
sqlChange.Parameters("@interupt_time").Value =
txtInterruptMin.Text
sqlChange.Connection = cnnChange
cnnChange.Open()
Try
sqlChange.ExecuteNonQuery()
lblSuccess.Visible = True
btnSuccess.Visible = True
Catch ex As Exception
lblFail.Visible = True
btnFail.Visible = True
lbTest.Text = sqlChange.CommandText
Finally
cnnChange.Close()
End Try
End If
Here is the stored proc code:
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE procedure sp01_InsertChange
--items inserted into tbl01_event
@it_emp_resp_id int,
@emp_requestor varchar(50),
@obj_affected_id int,
@subject varchar(8000),
@reason varchar(8000) = 'Null',
@priority char(2) = 'Null',
@comments varchar(8000) = 'Null',
@service_interupt char(2),
@dt_implement_sched datetime,
@dt_implement_act datetime,
@interupt_time decimal(18) = 'Null',
--items inserted into tbl04_doc_created
@event_id int output --generated from insert into tbl01_event
as
begin
--tbl01_event insert
insert into
tbl01_event(it_emp_resp_id,emp_requestor,dt_event,obj_affected_id,subject,
reason,
priority,comments,service_interupt,dt_implement_sched,dt_implement_act,
interupt_time,dt_created,dt_modified)
values(@it_emp_resp_id,@emp_requestor,getdate(),@obj_affected_id,@subject,
@reason,
@priority,@comments,@service_interupt,@dt_implement_sched,@dt_implement_act,
@interupt_time,getdate(),getdate())
select @event_id = @@identity
end
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO