Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

c# .NET MSSQL: run stored procedure

Posted on 2009-04-15
5
Medium Priority
?
675 Views
Last Modified: 2013-12-17
Hi All,

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


Thanks
0
Comment
Question by:detox1978
  • 2
  • 2
5 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24152562
0
 
LVL 26

Assisted Solution

by:Anurag Thakur
Anurag Thakur earned 400 total points
ID: 24152568
0
 
LVL 26

Expert Comment

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

Author Comment

by:detox1978
ID: 24153457
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
        FeedbackDataAccess.CreateFeedback(txtFeedback.Text);
 
    }
 
 
    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;
        comm.Parameters.Add(param);
 
        try
        {
            GenericDataAccess.ExecuteNonQuery(comm);
        }
        catch
        {
 
        }
    }

Open in new window

0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 600 total points
ID: 24153492
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.
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Suggested Courses

580 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