Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Team,
I have store procedure which is generated by c# code in windows forms - richtext box. How can I store this store procedure in sql sever by clicking of one command button.

What I have tried:

Tried as below...
if (rtbSPQuery.Text != "")
            {
                string execQuery = rtbSPQuery.Text;
                SqlConnection con = new SqlConnection(ProjectConnection.conStr);

                try
                {
                    con.Open();
                    SqlCommand comSaveSP = new SqlCommand("exec"+execQuery, con);
                    comSaveSP.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    con.Close();
                }
Posted
Updated 20-Feb-17 0:11am

I gotta say this doesn't seem like a very good idea. If your app gets hacked, someone could write a stored proc to your database that a) wipes all the data, and/or b) steals all the data, and/or uses the sql server as a spam bot, and/or any other number of evil deeds.
 
Share this answer
 
Comments
Karthik_Mahalingam 20-Feb-17 6:54am    
5
The same way you "save" any stored procedure in SQL: Issue a CREATE PROCEDURE or ALTER PROCEDURE command and execute it at the server.
CREATE PROCEDURE (Transact-SQL)[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900