Hai Sir,
How to add new column for the existing database table by inserting a column from the front end in .Net?
Hai Sir,
How to add new column for the existing database table by inserting a column from the front end in .Net?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Pankaj Kumar ChoudharyPosted May 22, 2015, 6:25 AM
as
begin
Declare @Query nvarchar(max);
if(@IsNull=0)
Set @Query=N'Alter Table '+QUOTENAME(@Table_Name)+' Add '+QUOTENAME(@Col_Name)+' '+QUOTENAME(@Data_Type)
else
Set @Query=N'Alter Table '+QUOTENAME(@Table_Name)+'Add'+QUOTENAME(@Col_Name)+QUOTENAME(@Data_Type)+'Not Null'
EXECUTE sp_executesql @Query
end
Pankaj Kumar ChoudharyPosted May 22, 2015, 6:22 AM
GO
/****** Object: StoredProcedure [dbo].[Alter_Table] Script Date: 5/22/2015 3:44:29 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER Proc [dbo].[Alter_Table](@Table_Name nvarchar(50),@Col_Name nvarchar(50),@Data_Type nvarchar(50),@IsNull bit)
as
begin
Declare @Query nvarchar(max);
if(@IsNull=0)
Set @Query=N'Alter Table '+QUOTENAME(@Table_Name)+' Add '+QUOTENAME(@Col_Name)+' '+QUOTENAME(@Data_Type)
else
Set @Query=N'Alter Table '+QUOTENAME(@Table_Name)+'Add'+QUOTENAME(@Col_Name)+QUOTENAME(@Data_Type)+'Not Null'
EXECUTE sp_executesql @Query
end
Sivaraman DhamodaranPosted May 22, 2015, 6:22 AM
Sivaraman DhamodaranPosted May 22, 2015, 6:18 AM
Sanjay SabariyaPosted May 22, 2015, 6:14 AM
alter table [tablename] add [ProductId] int default 0 NOT NULLKanaparthi Sureshma ReddyPosted May 22, 2015, 6:02 AM
Pankaj Kumar ChoudharyPosted May 22, 2015, 5:51 AM
String Str="Alter Table Table_Name Add Column_Name Datatype";
SqlCommand Com = new SqlCommand( Str,Con);
Com.ExecuteNonQuery() ;
Con.Close();
Sanjay SabariyaPosted May 22, 2015, 5:31 AM