none
How to pass stored procedure two input parameters in wcf service? RRS feed

  • Question

  • I am creating stored procedure with two input parameters,

    I want to use that two input parameters in my wcf service method ,

    How can i use stored procedure two input parameters in wcf service?


    anilbabu

    Wednesday, October 1, 2014 6:06 PM

Answers

  • Hi anil33,

    Oracle is out of our support range, please try to post it to the Oracle forum.

    Thanks for your understanding.

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, October 2, 2014 4:35 AM
    Moderator

All replies

  • Hi anil33,

    Pasting two input parameters to the stored procedure in the WCF Service method is just the same way as you did it in the Web Form or others.

    For more information, please try to refer to the following code which comes from here:

    The stored procedure:

    create procedure Proc_name (@param1 varchar(100), 
           @param2 varchar(100)) 
    as 
    insert into table1 values(@param1, @param2)

    Then the code (a C# example using ADO.NET):

    using (SqlConnection connection = new SqlConnection(connectionString))
    {
        // Create the command and set its properties.
        SqlCommand command = new SqlCommand();
        SqlCommand command = new SqlCommand 
           ("Proc_name", connection); 
    
        command.CommandType = CommandType.StoredProcedure;
    
        // Add the input parameters and set the properties.
        SqlParameter parameter1 = new SqlParameter();
        parameter.ParameterName = "@Param1";
        parameter.SqlDbType = SqlDbType.NVarChar;
        parameter.Direction = ParameterDirection.Input;
        parameter.Value = param1;
    
        SqlParameter parameter2 = new SqlParameter();
        parameter.ParameterName = "@Param2";
        parameter.SqlDbType = SqlDbType.NVarChar;
        parameter.Direction = ParameterDirection.Input;
        parameter.Value = param2;
    
        // Add the parameter to the Parameters collection. 
        command.Parameters.Add(parameter1);
        command.Parameters.Add(parameter2);
    
        // Open the connection and execute the reader.
        connection.Open();
        SqlDataReader reader = command.ExecuteNonQuery();
        reader.Close();
    }

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Thursday, October 2, 2014 2:27 AM
    Moderator
  • Hi anil33,

    Oracle is out of our support range, please try to post it to the Oracle forum.

    Thanks for your understanding.

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, October 2, 2014 4:35 AM
    Moderator