none
Using ExecuteStoreCommand to execute a stored procedure RRS feed

  • Question

  • Hi all,

    I know I can use ExecuteStoreCommand to execute a stored procedure, but what I am having a hard to figuring out is how to format the parameters so that the stored proc can recognize them.

    What I currently have is this.

    ///

     

     

    SqlParameter p = new SqlParameter { ParameterName = "@PersonName", Value = PersonList.SelectedText };

     

     

    string p = txtPerson.Text;

     

     

    using (var entityTestingContext = new EntityTestingEntities())

    {

    entityTestingContext.ExecuteStoreCommand(

     

    "exec spDeletePerson", p);

     

    }

    But I get the following error when trying to execute it. I tried the commented out code too and it doesn't work either.  I can't find any examples online at all. 

    Please help.  This should be easy but it's getting very frustrating.

    Rhonda

    Procedure or function 'spDeletePerson' expects parameter '@PersonName', which was not supplied.

    Tuesday, December 8, 2009 10:19 PM

Answers

  • Hello,

    Welcome to ADO.NET Entity Framework and LINQ to Entities forum!

    I think you are using the EF4 in VS2010 Beta 2.  To run the stored procedure spDeletePerson, you can refer to the following codes:
    ==============================================================
    string name = “Name”;
    context.ExecuteStoreCommand(“exec spDeletePerson @PersonName={0}”,  name);
    ==============================================================

     

    Have a nice day!


    Best Regards,
    Lingzhi Sun


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Friday, December 11, 2009 6:23 AM
    Moderator

All replies

  • Hello,

    Welcome to ADO.NET Entity Framework and LINQ to Entities forum!

    I think you are using the EF4 in VS2010 Beta 2.  To run the stored procedure spDeletePerson, you can refer to the following codes:
    ==============================================================
    string name = “Name”;
    context.ExecuteStoreCommand(“exec spDeletePerson @PersonName={0}”,  name);
    ==============================================================

     

    Have a nice day!


    Best Regards,
    Lingzhi Sun


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Friday, December 11, 2009 6:23 AM
    Moderator
  • Hi!

    I'm trying to use ExecuteStoreCommand in the Entity Framework.

    I have an SP that needs a UNIQUEIDENTIFIER as a parm, and I wanted to use a SqlParameter with SqlDbType.Uniqueidentifier.

    But the only way I can get this to work is by passing a plain string instead... 

    context.ExecuteStoreCommand(

     

    "Customer_Delete @cusRowID={0}", txtCusRowID.Text.ToString());

    It works, but it's ugly.   The 'right' code should look something like the first entry in this blog.

    Does anyone know if this is a bug in EF?  

    -John Baerg

     

    Tuesday, March 15, 2011 8:53 PM
  • Hi John,

    Could you please open a new thread to discuss the issue?   Please let me know the URL of the new thread.

    Have a nice day!

    Thanks


    Michael Sun [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Wednesday, March 16, 2011 1:09 AM
    Moderator