call stored proc c#

using (SqlConnection conn = new SqlConnection("Server=(local);DataBase=Northwind;Integrated Security=SSPI")) {
    conn.Open();

    // 1.  create a command object identifying the stored procedure
    SqlCommand cmd  = new SqlCommand("CustOrderHist", conn);

    // 2. set the command object so it knows to execute a stored procedure
    cmd.CommandType = CommandType.StoredProcedure;

    // 3. add parameter to command, which will be passed to the stored procedure
    cmd.Parameters.Add(new SqlParameter("@CustomerID", custId));

    // execute the command
    using (SqlDataReader rdr = cmd.ExecuteReader()) {
        // iterate through results, printing each to console
        while (rdr.Read())
        {
            Console.WriteLine("Product: {0,-35} Total: {1,2}",rdr["ProductName"],rdr["Total"]);
        }
    }
}

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
C# using a stored proc c# execute sql stored procedure i don't want to execute stored procedure i want to execute sql query in c# c# calling stored procedure how to execute a proceedure reading sql data with a parameter in c# how to call a SP from C# add stored procedure with c# how to use stored procedures in c# use stored procedure in c# c# sql for calling stored procedure stored procedure sql from c# call procedure in c# visual studio c# call stored procedure SQL server rcall stored procedure inside c# call sproc from c# code procedure that calls an sql command c# query or sql procedure sql client stored procedure how to run stored procedure in c# call a stored procedure from c# stored procedure for calling data in C# c# call database stored procedure sqlclient sqlcommand exec stored procedure c# connect to sql server and execute stored procedure execute a stored procedure from C# code sqlclient execute stored procedure sql query c# stored procedure execute sql server stored procedure in c# c# connect to database and execute stored procedure c# sql query stored procedure C# run proc call system stored procedure sql server c# c# mssql stored procedure call sql command execute stored procedure .net execute stored procedure c# DatabaseConnectionInfo.Connection stored procedure C# cSQlConnection stored procedure code stroed procedure c# call stored procedure from c# c# store sql command exec stored procedure in c# call stored procedure c# c# sql command execute stored procedure sql connection with stored procedure c# c# create and run stored procedure run sp in c# execute sp c# run stored procedure c# c# exec procedure read stored procedure c# execute stored procedure c# c# connect to stored procedure c# stored procedure run sql comman c# from stored procedure c# call sql stored procedure c# run stored procedure fastest way to call a sproc in c# c# execute stored procedure how to run sotred procedue c# can not execeute stored procedure on form load in c# c# call stored procedure c# call sql server stored procedure how to call stored procedure in c# sqlcommand stored procedure c# sqlparameter execute sp sp c# call stored procedure c# connection string run an sql exec in c# c# class to execute stored procedure create a class to call stored procedure in c# stored procedure c# c# sql command stored procedure sqlconnection stored procedure c# method to execute a stored procedure c# class method to execute a stored procedure c# use database name command stored procedure c# how to use stored procedure in c# call stored procedure in c# sql stored procedure call c# c# call sql procedure how to call a stored procedure in c# procedue c# sql execute stored procedure c#
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source