Chris Lombardi
Chris Lombardi

Reputation: 891

Code Error While Using SQL Output and ASP.NET

I have the below stored procedure in SQL Server 2008 which is not generating any errors in SQL, but is generating one in the web application which states "'GetGenInfo_Delete01_01_22' expects parameter '@FPath', which was not supplied". I am fairly novice at SQL, but what I am trying to do is return a field to VB.NET before the row is deleted. Any suggestions would be very helpful.

ALTER Procedure  [dbo].[GetGenInfo_Delete01_01_22]
   @IDX int,
   @FPath varchar(100) OUTPUT
AS
Begin
SELECT @FPath  = (SELECT FilePath FROM GenInfo_E1_01_22 Where ID=@IDX) 

DELETE 
FROM GenInfo_E1_01_22
WHERE ID = @IDX
END

Here is the VB code calling the stored proc

                Using con As New SqlConnection(connstr)
        Using cmd As New SqlCommand()
            cmd.CommandType = CommandType.StoredProcedure
            cmd.CommandText = "GetGenInfo_Delete01_01_22"
            cmd.Parameters.Add("IDX", ID)
            Dim returnParameter = cmd.Parameters.Add("@FPath", SqlDbType.VarChar)
            returnParameter.Direction = ParameterDirection.ReturnValue
            cmd.Connection = con
            con.Open()
            GridView1.DataSource = cmd.ExecuteReader()
            GridView1.DataBind()
            con.Close()
        End Using
    End Using

Upvotes: 0

Views: 89

Answers (2)

Melanie
Melanie

Reputation: 3111

You could add an FPath parameter to cmd. Do it like this:

SqlParameter fpath = new SqlParameter();
fpath.Direction = ParameterDirection.Output;
fpath.ParameterName = "@FPATH";
cmd.Parameters.Add(p);

Upvotes: 0

Yuriy Galanter
Yuriy Galanter

Reputation: 39807

You're creating parameter returnParameter, but you're not adding it to the parameters collection. Use cmd.Parameters.Add(returnParameter) prior to DB Call.

Upvotes: 1

Related Questions