I have written one sample Sql stored procedure.
USE [Db]
VB.NET
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[usp_TestProcedure]
AS
BEGIN
SET NOCOUNT ON;
PRINT 'Good evening'
ENDIts working fine. Now I want to read and alter this stored procedure (and db object like function and view) using c#. Can it be done using c# ?
I am using Server 2014 and C#4.5.
Manoj BhoirRank #599 · 4K pointsPosted May 21, 2015, 10:21 PM EDT
Why not? You can alter any type of SQL Object like Table, View, Function, Store Procedure using ALTER Command. You can Use SQLCommand Class and ExecuteNonQuery method.
See below sample code which will show you how to alter table and add new column :
string execSQL = "DECLARE @sup nvarchar(15); " + "SET @sup = '" + suppliernotxt + "'; " + "EXEC ('ALTER TABLE ProductNormalDB ADD ' + @sup + ' nvarchar(20) NULL')" SqlCommand cmd2 = new SqlCommand(execSQL, con); // Here con is your SQLConnection Object. cmd2.ExecuteNonQuery();Same you can use for other objects of SQL Server.