c# .NET MSSQL: run stored procedure

Posted on 2009-04-15
Last Modified: 2013-12-17
Hi All,

What is the syntax to run a stored procedure in c#

Question by:detox1978
    LVL 142

    Expert Comment

    by:Guy Hengel [angelIII / a3]
    LVL 26

    Assisted Solution

    by:Anurag Thakur
    LVL 26

    Expert Comment

    by:Anurag Thakur
    sorry a little late as its the same link
    LVL 2

    Author Comment

    I've created a stored procedure and tested it works.

    I've put together the code snipet below, but get the following error;

    "Compiler Error Message: CS0161: 'FeedbackDataAccess.CreateFeedback(string)': not all code paths return a value"

    Any ideas?
        protected void btnSubmit_Click(object sender, EventArgs e)
            //first create the customer
        public static int CreateFeedback(string myfeedback)
            // get a configured DbCommand object
            SqlCommand comm = GenericDataAccess.CreateCommand();
            // set the stored procedure name
            comm.CommandText = "App_AddFeedback";
            // create a new parameter
            SqlParameter param = comm.CreateParameter();
            // declair variable(s) to pass to the stored procedure
            param.ParameterName = "@myfeedback";
            param.Value = myfeedback;
            param.SqlDbType = SqlDbType.Text;

    Open in new window

    LVL 142

    Accepted Solution

    you have:
    public static int CreateFeedback(string myfeedback)

    but nowhere a return <something> in the procedure.
    so, either change to:
    public static void CreateFeedback(string myfeedback)

    or put some return statement into the functioncode.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
    For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
    Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
    Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now