I want to add one column to an existing table in C#, if it doesn't already exist. I know I have to use an 'alter table' command.
But I am not able to fire that command in my C# code.
How can I do?
I'm using Visual Studio 2010 and Sql Server 2008.
I want to add one column to an existing table in C#, if it doesn't already exist. I know I have to use an 'alter table' command.
But I am not able to fire that command in my C# code.
How can I do?
I'm using Visual Studio 2010 and Sql Server 2008.
this :
Use [DatabaseName]
Go
if Not exists( Select * from sys.columns As clm
where clm.object_id = OBJECT_ID(N'[TableName]')
And clm.name = N'[ColumnName]'
)
Begin
Alter Table TableName
Add ColumnName DataTypeName
End