locked
Parameters in Stored Procedure RRS feed

  • Question

  •  

    Parameters are passed to Stored Procedure from VB.NET Application like

    Dim param As SqlParameter
    param = New SqlParameter("@name",DbType.String)
    param.Direction = ParameterDirection.Input
    param.Value = "ABC"
    comand.Parameters.Add(param)

    But is there any way to specify parameters without specifying the
    parameter name and type like

    Dim param As SqlParameter
    param = New SqlParameter
    param.Direction = ParameterDirection.Input
    param.Value = "ABC"
    comand.Parameters.Add(param)


    But when i try like this i am getting an error saying that "Parameter1 is not a parameter in the procedure"...
    Can anybody tell me how to solve this .
    Thanx in advance

    Thursday, February 14, 2008 11:50 AM

Answers

  • Try making the parameter names in the stored procedure @parameter1 varchar(20), @parameter2 int.

     

    This isn't very descriptive to anyone using your procedures, but it should work.

     

     

    Friday, February 15, 2008 2:02 AM
  • You have to give it the names so that it knows which parameter to bind the value to the only other way is to write a Command.Text as "EXEC dbo.procedurename @id =@parameter1, @name = @parameter2" and then you just add the parameters?  What is the reason you don't want to use the names?

     

    Friday, February 15, 2008 12:54 PM

All replies

  • Try making the parameter names in the stored procedure @parameter1 varchar(20), @parameter2 int.

     

    This isn't very descriptive to anyone using your procedures, but it should work.

     

     

    Friday, February 15, 2008 2:02 AM
  • hai Jonathan

    it will work ... bcoz by default it will take the parameter name as Prameter1, Parameter2

    and so on... but i cannot change the stored procedure ... thats the problem..

    so is there any other way ?

    if theres plz do reply ..

    Thanx

    Friday, February 15, 2008 5:14 AM
  • You have to give it the names so that it knows which parameter to bind the value to the only other way is to write a Command.Text as "EXEC dbo.procedurename @id =@parameter1, @name = @parameter2" and then you just add the parameters?  What is the reason you don't want to use the names?

     

    Friday, February 15, 2008 12:54 PM