locked
Passing parameters to stored procedure RRS feed

  • Question

  • I have a web service which takes in stored procedure name and parameters as argument, so basically when this webservice is called it executes that stored procedure with those parameters. Now I am trying to call this webservice and pass parameters and having little hard time how to do it. Can anyone help me with this?
    creativity..
    Monday, January 26, 2009 2:07 PM

Answers

  • hi,

    You could use a code like following, to set parameter values,

    //Creating parameter array 
    SqlParameter[] parms = new SqlParameter[2]; 
     
    //Assign new Parameter objects to array 
    parms[0] = new SqlParameter(); 
    parms[1] = new SqlParameter(); 
     
    //Set properties to parameter object, here used only the object 0 
    parms[0].ParameterName = "Parameter name"
    parms[0].SqlDbType = SqlDbType.Int; 
    parms[0].SqlValue = 100; 
    parms[0].Direction = ParameterDirection.Input; 

    Asanga.


    Monday, January 26, 2009 4:04 PM

All replies

  •  

    If you have a SQL Server database, then you'll need to create SqlParameter.

    Be carefull and make sure the webservice will not allow people to execute system store proc.


    Puzzles, brain teases, riddles, enigmas: http://www.toysforthebrain.com
    Monday, January 26, 2009 2:30 PM
  • thanks..  now that i have 2 parameters. 

     

    SqlParameter[] params = New SqlParameter[]

     

    Table = webService.GetInfo('storedprocedure', params)

     

    How do i add value in SqlParameter?


    creativity..
    Monday, January 26, 2009 2:35 PM
  • hi,

    You could use a code like following, to set parameter values,

    //Creating parameter array 
    SqlParameter[] parms = new SqlParameter[2]; 
     
    //Assign new Parameter objects to array 
    parms[0] = new SqlParameter(); 
    parms[1] = new SqlParameter(); 
     
    //Set properties to parameter object, here used only the object 0 
    parms[0].ParameterName = "Parameter name"
    parms[0].SqlDbType = SqlDbType.Int; 
    parms[0].SqlValue = 100; 
    parms[0].Direction = ParameterDirection.Input; 

    Asanga.


    Monday, January 26, 2009 4:04 PM