C# to Update a Store Procedure

Ok based on the previous post, you now know how to get the store procedures in a table, now you need to get the actual content.

To do so, you need to execute the command sp_helptext ‘store_procedure’

In a very nice way you can do the following to convert to string

DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = getCommand(“exec sp_helptext ” + procedureName);
catch (System.Exception ex)
return “”;
if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
StringBuilder output = new StringBuilder();
foreach(DataRow dr in ds.Tables[0].Rows){
return output.ToString();

return “”

Posted in Uncategorized

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>