February 26, 2009 at 1:04 am
VS VB 2008
SQL server 2008
Im trying to create a column in an existing table. I have been able to drop and rename columns but can not create. Can anyone see whats wrong with the code.
I'm getting the error 'Create failed for Table 'dbo.employees' on tb.create()
Thanks in advance.
Imports Microsoft.SqlServer.Management.Smo
Imports Microsoft.SqlServer.Management.Common
Function AddSQLColumn(ByVal Name As String) As Boolean
Dim svr As New Server(SERVER_NAME)
svr.ConnectionContext.LoginSecure = False
svr.ConnectionContext.Login = DB_USER
svr.ConnectionContext.DatabaseName = DATABASE_NAME
svr.ConnectionContext.Password = DB_PASSWORD
svr.ConnectionContext.Connect()
Dim db As Database = svr.Databases(DATABASE_NAME)
Dim tb As New Table(db, "employees")
Dim col As New Column(tb, Name, DataType.Int)
col.Nullable = True
tb.Columns.Add(col)
tb.Create()
End Function
February 26, 2009 at 1:12 am
Please don't cross post. It just wastes peoples time and fragments replies.
No replies to this thread please. Direct replies to: http://www.sqlservercentral.com/Forums/Topic664825-391-1.aspx
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
February 26, 2009 at 1:15 am
Sorry, my first post and made a mistake.
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply