Adding a column to an existing table

  • I am trying to add a table to a column via DMO. The code below gives me the error "Objext does not support this property or method". Can anyone see the mistake? I am new to DMO, and BOL doesn't seem to help.

    Thanks

    Private colm_COL_AUD As SQLDMO.Column

    Set colm_COL_AUD = New SQLDMO.Column

    colm_COL_AUD.Name = strm_NEW_FIELDS(i2)

    colm_COL_AUD.Datatype = DBM_COLUMN_TYPE(strgSQLDatabase, strm_TABLE, _ strm_NEW_FIELDS(i2))

    objgSQLServer.Databases("myAudit").Tables(strl_AUD_TABLE).BeginAlter

    objgSQLServer.Databases("myAudit").Tables(strl_AUD_TABLE).Columns.Add (colm_COL_AUD)

    objgSQLServer.Databases("myAudit").Tables(strl_AUD_TABLE).DoAlter

  • I think the problem is with the datatype= part. Normally this is just the one word data type descripion (char, varchar, etc). For some reason DMO does not give you intellisense on the data type, it really should have been coded as an enum so you could just pick the type.

    For other readers who may be interested in adding columns or in the very basics of objects, I've just posted a new articlehttp://www.sqlservercentral.com/columnists/awarren/addingacolumnusingsql_dmo.asp that you might find interesting. Or annoying depending on your view of DMO!

    Andy

  • Thanks Andy,

    The article was very useful. I think DMO is great for certain tasks, like creating metadata,triggers and other administrative tasks. What I don't think is very useful is when everything has to be done with it. Have I been asleep while the world changed, or is it only where I work that scripts has become a dirty word?

    Anyway, thanks again, I appreciate you taking the trouble.

  • I dont think scripts have become a dirty word. I think we have confusion sometimes where the line blurs. After all, it's entirely possibly to do everything in TSQL if that is your goal, or DMO. It comes down to which is 'more efficient' which is hard to quantify or which is more comfortable to work with based on your background. I think using either one exclusively leaves out some interesting possibilities.

    Andy

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply