IListManager::CreateFromSql
Use this method to create a list from a SQL query.
Definition
HRESULT IListManager::CreateFromSql(BSTRlistName,BSTRlistDesc,longlFlags,longuserFlags,BSTRconnStr,BSTRqueryStr,longerrLimit,BOOL bAsync,VARIANT*pvarOpID,VARIANT*pvarID);
Parameters
listName
[in] A BSTR that provides the name for the list.
listDesc
[in] A BSTR that provides a description for the list.
lFlags
[in] A long that specifies the bitmask flags that control the type of list created.
userFlags
[in] A long that contains application specific user flags. Not used by the ListManager object.
connStr
[in] A BSTR that contains the connection string for the SQL Server database.
queryStr
[in] A BSTR that contains the SQL query for retrieving the contents of the new list.
errLimit
[in] A long that is not used.
bAsync
[in] A BOOL that specifies whether the creation operation is performed synchronously or asynchronously. A value of True indicates asynchronous processing.
pvarOpID
[out, optional] A pointer to a VARIANT used to return an Operation ID.
pvarID
[out, retval] A pointer to a VARIANT used to return the ID of the new list.
Return Values
This method returns an HRESULT indicating whether or not it completed successfully. See the Error Values section for more details.
Error Values
This method returns S_OK (0x00000000) to indicate success and either standard or custom COM HRESULT error values to indicate failure. For more information about standard COM errors, see Standard COM Errors.
The following table shows the custom COM errors that this method can return.
Constant | Value | Description |
E_LM_CONNECTIONFAILED | 0x8C400001 | Failed to establish database connection. |
E_LM_INVALID_FLAGS | 0x8C400005 | Invalid flags value. |
E_LM_LIST_ALREADY_EXISTS | 0x8C400007 | The specified list has already been created. |
E_LM_MAILABLE_LIST_NO_EMAILS | 0x8C40000D | The list is designated as a Mailable list but does not contain an rcp_email column. |
E_LM_OPER_CANCELED | 0x8C40000B | The operation was canceled. |
E_LM_SQLERROR | 0x8C400003 | Error while executing SQL/ADO operation. |
E_LM_USER_LIST_NO_GUIDS | 0x8C40000E | The list is designated as a User list but does not contain an rcp_guid column. |
OLE_E_BLANK | 0x80040007 | The ListManager object has not been properly initialized. |
Additional information may be available using the global Err object, which can be accessed using the API function GetErrorInfo. In particular, the GetDescription method of the IErrorInfo interface may return a text description of the error.
Remarks
It is recommended to use the MSDASQL (ODBC) OLEDB provider with this method.
The CreateFromSQL method uses the T-SQL OpenRowset command to run the query against the database. Therefore, any ODBC data source may be specified with the following restriction:
If the SQLOLEDB provider is used, any object names used in the query must be fully qualified. For example, on SQL Server 7.0 databases, use "SELECT * FROM database.dbo.tablename" instead of "SELECT * FROM tablename".
For a list of possible values for the lflags parameter, see the GetListFlags method.
For more information about memory ownership issues related to COM property and method parameters, see Managing COM Parameter Memory.