SQL Server Native Client (OLE DB) 中的 ISSCommandWithParameters::SetParameterProperties

适用于:SQL ServerAzure SQL 数据库Azure SQL 托管实例Azure Synapse AnalyticsAnalytics Platform System (PDW)

重要

已从 SQL Server 2022 (16.x) 和 SQL Server Management Studio 19 (SSMS) 中移除 SQL Server Native Client(通常缩写为 SNAC)。 不建议在新的开发工作中使用 SQL Server Native Client OLE DB 提供程序(SQLNCLI 或 SQLNCLI11)和旧版 Microsoft OLE DB Provider for SQL Server (SQLOLEDB)。 此后请切换到新的 Microsoft OLE DB Driver (MSOLEDBSQL) for SQL Server

按照序号基于每个参数设置参数属性,或者通过指定 SSPARAMPROPS 结构数组来设置大容量参数属性。

语法

HRESULT SetParameterProperties(  
      DB_UPARAMS cParams,   
      SSPARAMPROPS rgParamProperties[]);  

参数

cParams[in]
rgParamProperties 数组中 SSPARAMPROPS 结构的数量 。 如果此数值为零,ISSCommandWithParameters::SetParameterProperties 将删除可能已经为该命令中的任何参数指定的所有属性 。

rgParamProperties[in]
要设置的 SSPARAMPROPS 结构数组。

返回代码值

ISSCommandWithParameters::SetParameterProperties 方法返回的错误代码与核心 OLE DB ICommandProperties::SetProperties 方法返回的错误代码相同 。

备注

允许按照序号基于每个参数使用此方法设置参数属性,或者在已经从属性数组生成 SSPARAMPROPS 之后使用单个 ISSCommandWithParameters::SetParameterProperties 调用设置参数属性 。

在调用 ISSCommandWithParameters::SetParameterProperties 方法之前,必须首先调用 SetParameterInfo 方法 。 调用 SetParameterProperties(0, NULL) 可清除所有指定的参数属性,而调用 SetParameterInfo(0,NULL,NULL) 则会清除所有参数信息(包括可能与某个参数相关的任何属性)。

调用 ISSCommandWithParameters::SetParameterProperties 以指定非DBTYPE_XML或DBTYPE_UDT类型的参数的属性,返回DB_E_ERRORSOCCURRED或DB_S_ERRORSOCCURRED,并使用DBPROPSTATUS_NOTSET标记该参数的 SSPARAMPROPS 中包含的所有 DBPROPS 的 dwStatus 字段。 应当遍历 SSPARAMPROPS 中包含的每个 DBPROPSET 的 DBPROP 数组,以检测 DB_E_ERRORSOCCURRED 或 DB_S_ERRORSOCCURRED 引用了哪些参数。

如果调用 ISSCommandWithParameters::SetParameterProperties 以指定尚未使用 SetParameterInfo 设置其参数信息的参数的属性,访问接口将返回 E_UNEXPECTED 并显示以下错误消息 :

在没有先调用 SetParameterInfo 方法的情况下,不能为指定参数调用 SetParameterProperties 方法。 在设置参数属性之前,必须首先设置参数信息。

如果对 ISSCommandWithParameters::SetParameterProperties 的调用包含某些参数,其中已设置了参数信息,而另一些参数未设置参数信息,则返回的 SSPARAMPROPS 属性集的 DBPROPSET 中的 dwStatus 属性将带有 DBSTATUS_NOTSET 。

SSPARAMPROPS 结构的定义如下所示:

struct SSPARAMPROPS {
    DBORDINAL iOrdinal;
    ULONG cPropertySets;
    DBPROPSET *rgPropertySets;
};

自 SQL Server 2012 (11.x) 起,借助数据库引擎中的改进,ISSCommandWithParameters::SetParameterProperties 可以获取预期结果的更准确描述。 这些更准确的结果可能与旧版 SQL Server 中 ISSCommandWithParameters::SetParameterProperties 返回的值有所不同。 有关详细信息,请参阅元数据发现

成员 说明
iOrdinal 所传递参数的序号。
cPropertySets rgPropertySets 中 DBPROPSET 结构的数量 。
rgPropertySets 指向内存中将返回 DBPROPSET 结构数组的位置的指针。

另请参阅

ISSCommandWithParameters (OLE DB)