Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How do you call parameterized stored procedure from c# with return data?

Posted on 2014-03-25
3
Medium Priority
?
559 Views
Last Modified: 2014-03-31
How can you call a sql server stored procedure while passing a parameter?

thanks

Nick
0
Comment
Question by:countyprob
3 Comments
 
LVL 21

Assisted Solution

by:Dale Burrell
Dale Burrell earned 1000 total points
ID: 39954786
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 39954796
from SSMS?

right-click on it, select "execute stored procedure ..." ,"execute to" and "new query editor window"

a sample will be created for you. just set values and you can execute it
0
 
LVL 21

Accepted Solution

by:
Tapan Pattanaik earned 1000 total points
ID: 39954972
Hi countyprob,

       con.Open();
        SqlCommand cmd = new SqlCommand("spuserdetail", con);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@UserName", UserName);
        cmd.Parameters.AddWithValue("@Password", Password);
        cmd.Parameters.AddWithValue("@Email", Email);
        cmd.Parameters.AddWithValue("@Country", Country);
        cmd.Parameters.Add("@ERROR", SqlDbType.Char, 500);
        cmd.Parameters["@ERROR"].Direction = ParameterDirection.Output;
        cmd.ExecuteNonQuery();
        message = (string)cmd.Parameters["@ERROR"].Value;
        con.Close();

Below link describes how to call a stored procedure  with parameter(input/output ) in C# in details. .
http://www.c-sharpcorner.com/UploadFile/rohatash/get-out-parameter-from-a-stored-procedure-in-Asp-Net/
0

Featured Post

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

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

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

972 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