can i call a stored procedure without knowing the names of its parameters

  • can i call a stored procedure without knowing the names of its parameters

    If I have a stored procedure.

    create Procedure dbo.Test_sp

    (

    @id int,

    @name varchar (50)

    )

    in my code from front end

    if I dont know the parameter names

    cmd.Parameters.Add ("@id",SqlInt).vlaue = 15

    Can I still make a call if I dont provide this @id?


    Regards,

    Muhammad Arsalan Ayub
    groups.yahoo.com

    Blog

  • The stored procedure would have to be declared with a default value for the parameter, then yes, you would not have to pass a value for it in.

  • When I used to program through ASP and Vbscript, you didn't need to know the parameter names - just the order of the parameters and the datatypes.

  • Try it like this:

    cmd.Parameters.Add (1,SqlInt).value = 15

    (or maybe 0?)

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]

  • I have checked this out the

    cmd.Parameters.Add (1, Int).value = 15

    is not possible

    Any other suggestions ?


    Regards,

    Muhammad Arsalan Ayub
    groups.yahoo.com

    Blog

  • Yeah, I just saw this the other day, but I don't have my Visual Studio up to test it.

    If you have yours up, edit the parameters of the "cmd.Parameters.Add (1, Int)" so that the intellisense comes up. delete all of the parmeters so that its like this: "cmd.Parameters.Add (". The Intellisense should then list the overloaded ADD parameter options, one of the should be either offset based or with no parameterID so that you just add them sequentially.

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]

  • Well I have checked that out

    There are is no such overloaded method for Add

    3 out of the 4 take the parameter name as a string and

    1 takes the SQLParameter.

    Have they changed the functionality or am i still missing on something.

    I guess this logic is not possible to implement; if so then how do we design the classes for the DB access, or the helper classes?

  • Yeah, I just looked it up and I cannot see hot to do it either (I must have been thinking about some other DB interface, like SMO or something).

    The only thing I could suggest is to switch the CommandType to Text and just pass it "EXEC {proc_name} {paramValue1}, {paramValue2}, ...".

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply