Hello
I am having trouble returning a value from a stored procedure and displaying it in a text box on my ASP.NET page.
I have had success with ParameterDirection.ReturnValue but I only get 0 when using ParameterDirection.Output
Could someone help by pointing out the error in my ASP.NET code or stored procedure (code below)
The stored procedure is entering data correctly into the table.
Thanks
Dave
CREATE Procedure dbo.sp_AT_Request
(@ProjectNo int,@TmpQuery int OUTPUT)
AS
CREATE TABLE #RN (var int)
SELECT @TmpQuery=
Case when max(requestno) is null
then 1
else max(RequestNo)+1
end
from AT_Request
where ProjectNo = @ProjectNo
DROP TABLE #RN
SELECT @TmpQuery
insert into AT_Request
(ProjectNo , RequestNo )
values
(@ProjectNo, @TmpQuery)
Return @TmpQuery
GO
Protected Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
conn.ConnectionString = Application.Item("connection_string")
Dim Cmd As New SqlClient.SqlCommand
Cmd.Connection = conn
Cmd.CommandText = "dbTicketTracking.dbo.sp_AT_REQUEST"
Cmd.CommandType = CommandType.StoredProcedure
Dim Prm1 As New SqlClient.SqlParameter("@ProjectNo", SqlDbType.VarChar)
Prm1.Direction = ParameterDirection.Input
Cmd.Parameters.Add(Prm1)
Prm1.Value = 5
Dim Prm2 As New SqlClient.SqlParameter("@TmpQuery", SqlDbType.Int)
Cmd.Parameters.Add("@TmpQuery", SqlDbType.Int).Direction = ParameterDirection.Output
conn.Open()
Dim reader As SqlClient.SqlDataReader = Cmd.ExecuteReader()
Dim retParam As String = CType(Cmd.Parameters("@TmpQuery").Value, String)
Dim retParam2 As Integer = Cmd.Parameters("@TmpQuery").Value
conn.Close()
TB_Test.Text = retParam2 ' returns 0
End Sub
I am having trouble returning a value from a stored procedure and displaying it in a text box on my ASP.NET page.
I have had success with ParameterDirection.ReturnValue but I only get 0 when using ParameterDirection.Output
Could someone help by pointing out the error in my ASP.NET code or stored procedure (code below)
The stored procedure is entering data correctly into the table.
Thanks
Dave
CREATE Procedure dbo.sp_AT_Request
(@ProjectNo int,@TmpQuery int OUTPUT)
AS
CREATE TABLE #RN (var int)
SELECT @TmpQuery=
Case when max(requestno) is null
then 1
else max(RequestNo)+1
end
from AT_Request
where ProjectNo = @ProjectNo
DROP TABLE #RN
SELECT @TmpQuery
insert into AT_Request
(ProjectNo , RequestNo )
values
(@ProjectNo, @TmpQuery)
Return @TmpQuery
GO
Protected Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
conn.ConnectionString = Application.Item("connection_string")
Dim Cmd As New SqlClient.SqlCommand
Cmd.Connection = conn
Cmd.CommandText = "dbTicketTracking.dbo.sp_AT_REQUEST"
Cmd.CommandType = CommandType.StoredProcedure
Dim Prm1 As New SqlClient.SqlParameter("@ProjectNo", SqlDbType.VarChar)
Prm1.Direction = ParameterDirection.Input
Cmd.Parameters.Add(Prm1)
Prm1.Value = 5
Dim Prm2 As New SqlClient.SqlParameter("@TmpQuery", SqlDbType.Int)
Cmd.Parameters.Add("@TmpQuery", SqlDbType.Int).Direction = ParameterDirection.Output
conn.Open()
Dim reader As SqlClient.SqlDataReader = Cmd.ExecuteReader()
Dim retParam As String = CType(Cmd.Parameters("@TmpQuery").Value, String)
Dim retParam2 As Integer = Cmd.Parameters("@TmpQuery").Value
conn.Close()
TB_Test.Text = retParam2 ' returns 0
End Sub