﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Programming / General  / how to run a  stored procedure from C# application / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Sun, 19 May 2013 22:58:26 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: how to run a  stored procedure from C# application</title><link>http://www.sqlservercentral.com/Forums/Topic454929-23-1.aspx</link><description>You can check this article [url=http://www.shahriarnk.com/Shahriar-N-K-Research-Embedding-SQL-in-C-Sharp-Java.html]HOW TO: SQL &amp; C#[/url] to learn how to call a stored procedure in a MS SQL database from a C# application as well as a Java application.You will learn how to pass parameters to the stored procedures as well as read Out parameters returned by the sp.Also, you will learn to how pass parameterized SQL queries from the application and read data returned by the queries.[url=http://www.shahriarnk.com/]Shahriar Nour Khondokar[/url]</description><pubDate>Wed, 02 Jun 2010 07:07:19 GMT</pubDate><dc:creator>shr_khr</dc:creator></item><item><title>RE: how to run a  stored procedure from C# application</title><link>http://www.sqlservercentral.com/Forums/Topic454929-23-1.aspx</link><description>If all you want to do is execute a stored proc that returns no results then you don't need a DataAdapter/DataSet (you don't necessarily need one even if you do want a resultset -- it depends on what you want to do with the results). You also don't need the "Exec" in your command text is you set the CommandType property of your SqlCommand to "StoredProcedure".[font="Courier New"]string connectionString = "(your connection string here)";string commandText = "usp_YourStoredProc";using (SqlConnection conn = new SqlConnection(connectionString)){	SqlCommand cmd = new SqlCommand(commandText, conn);	cmd.CommandType = CommandType.StoredProcedure;	cmd.CommandTimeout = 600;	conn.Open();	int affectedRows = cmd.ExecuteNonQuery();	conn.Close();}[/font]If you want to pass parameters, it'd also be better to define SqlParameter objects for the parameters, set their values, then add those to the command object, rather than concatenating them into the command text.</description><pubDate>Fri, 29 Feb 2008 07:31:16 GMT</pubDate><dc:creator>dmbaker</dc:creator></item><item><title>RE: how to run a  stored procedure from C# application</title><link>http://www.sqlservercentral.com/Forums/Topic454929-23-1.aspx</link><description>Try this. Just paste the code into a button's click event. You'll need to change the items shown bold to match your database settings. string oConnString = [b]"Data Source=localhost;Initial Catalog=ALocalDataBase;Integrated Security=True"[/b];SqlConnection oConn = new SqlConnection(oConnString);SqlCommand oCmd = new SqlCommand("Exec [b]sp_AnSProc[/b]", oConn);SqlDataAdapter oAdptr = new SqlDataAdapter(oCmd);DataSet oDS = new DataSet();oConn.Open();oCmd.ExecuteNonQuery();oCmd.CommandTimeout = 600;oAdptr.Fill(oDS);//uncomment the following line to view the xml representation of the data returned//System.Diagnostics.Debug.WriteLine(oDS.GetXml());oConn.Close();[b]Note: [/b]If your stored procedure requires that parameters be passed in, just use String Concatenation. Good luck. I hope this helps.</description><pubDate>Wed, 27 Feb 2008 23:37:39 GMT</pubDate><dc:creator>Programmer07</dc:creator></item><item><title>how to run a  stored procedure from C# application</title><link>http://www.sqlservercentral.com/Forums/Topic454929-23-1.aspx</link><description>how to run a stored procedure from C# application</description><pubDate>Wed, 13 Feb 2008 03:33:41 GMT</pubDate><dc:creator>sankar18</dc:creator></item></channel></rss>