Monday, February 20, 2012

Please Help, Procedure sp_displaylabels expects parameter @mod_id, which was not supplied

Procedure 'sp_displaylabels' expects parameter '@.mod_id', which was not supplied.

I get the error at the SQLAdptr1.Fill(DS): Procedure 'sp_displaylabels' expects parameter '@.mod_id', which was not supplied.

But i am passing the @.mod_id value in the string Valmodid.


Private Sub BindData()
Dim DS As New DataSet
Dim SQLCmd1 As New SqlCommand
Dim moduleId As New SqlParameter
Dim Valmodid As String

Valmodid = Request.QueryString("modid")

moduleId = SQLCmd1.Parameters.Add("@.mod_id", Valmodid)

SQLCmd1 = New SqlCommand("sp_displaylabels", MyConnection)

Dim SQLAdptr1 As SqlDataAdapter = New SqlDataAdapter(SQLCmd1)

SQLAdptr1.Fill(DS)

MyDataGrid.DataSource = DS
MyDataGrid.DataBind()
End Sub

'''My Stored Procedure code:
CREATE PROCEDURE [dbo].[sp_displaylabels]
(
@.mod_id nvarchar(10)
)
AS
SELECT *
FROM tbl_labels
where module_id=@.mod_id ORDER BY id ASC
GO

You're adding your parameter before you instantiate you SqlCommand. Try moving the parameter.Add below the instantiation.

If that doesn't work:

You might have to set the CommandType to SQLCmd1 after you instantiate it. SQLCmd1.CommandType = CommandType.StoredProcedure;

Sorry, haven't tested this yet.

No comments:

Post a Comment