sp_OAGetProperty 和 sp_OASetProperty 的 propertyname 參數(shù)以及 sp_OAMethod 的 methodname 支持對(duì)象層次結(jié)構(gòu)語(yǔ)法類(lèi)似于 Microsoft® Visual Basic®。當(dāng)使用該特殊語(yǔ)法時(shí),這些參數(shù)有下列通用格式:
'TraversedObject.PropertyOrMethod'
TraversedObject
是存儲(chǔ)過(guò)程中指定的在層次結(jié)構(gòu)中位于 objecttoken 下的 OLE 對(duì)象。使用 Visual Basic 語(yǔ)法指定一系列集合、對(duì)象屬性和返回對(duì)象的方法。系列中的每個(gè)對(duì)象指定符必須用句號(hào) (.) 隔開(kāi)。
系列中的項(xiàng)目可以是集合名。使用下面的語(yǔ)法指定集合:
Collection("item")
必須用雙引號(hào) (") 將 item 括起來(lái)。不支持用于集合的 Visual Basic 感嘆號(hào) (!) 語(yǔ)法。
PropertyOrMethod
是 TraversedObject 屬性或方法的名稱(chēng)。
若要通過(guò)使用 sp_OAGetProperty、sp_OASetProperty 或 sp_OAMethod 參數(shù)(包括支持 sp_OAMethod 輸出參數(shù))指定所有索引或方法參數(shù),請(qǐng)使用下面的語(yǔ)法:
PropertyOrMethod
若要在圓括號(hào)內(nèi)指定所有索引或方法參數(shù)(將導(dǎo)致忽略 sp_OAGetProperty、sp_OASetProperty 或 sp_OAMethod 的所有檢索或方法參數(shù)),請(qǐng)使用下面的語(yǔ)法:
PropertyOrMethod( [ParameterName :=] "parameter" [,...] )
必須用雙引號(hào) (") 將每個(gè)參數(shù)括起來(lái)。指定所有位置參數(shù)后才能指定命名參數(shù)。
如果沒(méi)有指定 TraversedObject,則必需有 PropertyOrMethod。
如果沒(méi)有指定 PropertyOrMethod,TraversedObject 將作為對(duì)象令牌輸出參數(shù)從 OLE 自動(dòng)化存儲(chǔ)過(guò)程返回。如果已指定 PropertyOrMethod,將調(diào)用 TraversedObject 的屬性或方法,且屬性值或方法返回值作為輸出參數(shù)從 OLE 自動(dòng)化存儲(chǔ)過(guò)程返回。
如果 TraversedObject 列表中的任何項(xiàng)目沒(méi)有返回 OLE 對(duì)象,則說(shuō)明發(fā)生了錯(cuò)誤。
有關(guān) Visual Basic OLE 對(duì)象語(yǔ)法的更多信息,請(qǐng)參見(jiàn) Visual Basic 文檔。
有關(guān) HRESULT 返回代碼的更多信息,請(qǐng)參見(jiàn) sp_OACreate 部分的"HRESULT 返回代碼"。
下面是使用 SQL-DMO SQLServer 對(duì)象的對(duì)象層次結(jié)構(gòu)語(yǔ)法示例。
-- Call the Connect method of the SQLServer object.相關(guān)文章
EXEC @hr = sp_OAMethod @object,
'Connect("my_server", "my_login", "my_password")'
-- Get the pubs..authors Table object.
EXEC @hr = sp_OAGetProperty @object,
'Databases("pubs").Tables("authors")',
@table OUT
-- Get the Rows property of the pubs..authors table.
EXEC @hr = sp_OAGetProperty @object,
'Databases("pubs").Tables("authors").Rows',
@rows OUT
-- Call the CheckTable method of the pubs..authors table.
EXEC @hr = sp_OAMethod @object,
'Databases("pubs").Tables("authors").CheckTable',
@checkoutput OUT