Solved

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

Posted on 2014-03-25
3
533 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 21

Assisted Solution

by:Dale Burrell
Dale Burrell earned 250 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 250 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

Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL syntax for max(date) 3 39
SQL: Transformation or Pivot 3 36
Migrate SQL 2005 DB to SQL 2016 4 32
ErrorKind in crystal reprot VB.Net 1 17
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.
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.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

751 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