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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Sanjay SabariyaRank #2,262 · 623 reputationPosted May 22, 2015, 1:31 AM EDT
using (DbCommand command = new SqlCommand("alter table [Product] add [ProductId] int default 0 NOT NULL",connection))Pankaj Kumar ChoudharyRank #80 · 24.4K reputationPosted May 22, 2015, 1:51 AM EDT
String Str="Alter Table Table_Name Add Column_Name Datatype";
SqlCommand Com = new SqlCommand( Str,Con);
Com.ExecuteNonQuery() ;
Con.Close();
Kanaparthi Sureshma Reddy80 reputationPosted May 22, 2015, 2:02 AM EDT
Sanjay SabariyaRank #2,262 · 623 reputationPosted May 22, 2015, 2:14 AM EDT
alter table [tablename] add [ProductId] int default 0 NOT NULLSivaraman DhamodaranRank #40 · 34.5K reputationPosted May 22, 2015, 2:18 AM EDT
Sivaraman DhamodaranRank #40 · 34.5K reputationPosted May 22, 2015, 2:22 AM EDT
Pankaj Kumar ChoudharyRank #80 · 24.4K reputationPosted May 22, 2015, 2:22 AM EDT
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
Pankaj Kumar ChoudharyRank #80 · 24.4K reputationPosted May 22, 2015, 2:25 AM EDT
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