hResult = m_pRecordset->Open ( TEXT("SELECT * FROM LinkmanList"),
_variant_t((IDispatch*)(((CUserManagerApp*)AfxGetApp())->m_pConnection), true),
adOpenDynamic,
adLockPessimistic,
adCmdText);
_variant_t((IDispatch*)(((CUserManagerApp*)AfxGetApp())->m_pConnection), true),
adOpenDynamic,
adLockPessimistic,
adCmdText);
经检查发现:
HRESULT hResult = m_pRecordset.CreateInstance (TEXT("ADODB.Recordset"));
错误出现在这里,何故?
创建记录集实例的代码就是这么写的!你的写法是错误的。
//***************************************************************************
// Function Name : InitLinkmanList()
// Parameter :
//
// Purpose : When user click the group name of the tree view, the
// listview show the relative users.
//***************************************************************************
bool CUserManagerDlg::InitLinkmanList(DWORD dwGroupID)
{
m_userList.DeleteAllItems (); //***********************************************************************
_variant_t vID;
_variant_t vGroupID;
_variant_t vLinkmanName;
_variant_t vEmail;
_variant_t vHandset; try
{
// Create the Recordset object
HRESULT hResult = m_pRecordset.CreateInstance (TEXT("ADODB.Recordset")); if(SUCCEEDED(hResult))
{
// Execute the SQL command
hResult = m_pRecordset->Open ( TEXT("SELECT ID,GroupID,LinkmanName,Email,Handset FROM LinkmanList"),
_variant_t((IDispatch*)(((CUserManagerApp*)AfxGetApp())->m_pConnection), true),
adOpenDynamic,
adLockPessimistic,
adCmdText); if(SUCCEEDED(hResult))
{
m_pRecordset->MoveFirst (); while( !m_pRecordset->adoEOF )
{
// Get the record of the GroupName
vGroupID = m_pRecordset->GetCollect (TEXT("GroupID")); vGroupID.ChangeType (VT_R4);
if ( (DWORD)(vGroupID.fltVal) != dwGroupID )
{
m_pRecordset->MoveNext ();
continue;
} // Get the record from the database
vID = m_pRecordset->GetCollect (TEXT("ID"));
vLinkmanName = m_pRecordset->GetCollect (TEXT("LinkmanName"));
vEmail = m_pRecordset->GetCollect (TEXT("Email"));
vHandset = m_pRecordset->GetCollect (TEXT("Handset")); // Show the information on the dialog
int nItem = m_userList.InsertItem (0xffff, (_bstr_t)vLinkmanName);
if(vEmail.vt != VT_NULL)
{
m_userList.SetItem (nItem, 1, 1, (_bstr_t)vEmail, NULL, 0, 0, 0);
} if(vHandset.vt != VT_NULL)
{
m_userList.SetItem (nItem, 2, 1, (_bstr_t)vHandset, NULL, 0, 0, 0);
} // Set the data attached the item in the listctrl
vID.ChangeType (VT_R4);
m_userList.SetItemData (nItem, (DWORD)vID.fltVal); // Move the pointer to the next
m_pRecordset->MoveNext ();
} }
else
{
return FALSE;
} }
else
{
return FALSE;
} }
// catch the expection error
catch(_com_error e)
{
char cErrorMessage[1024];
strcpy (cErrorMessage, (char*)(_bstr_t)(e.Description()) );
AfxMessageBox(cErrorMessage);
return FALSE;
} if(m_pRecordset)
{
m_pRecordset->Close ();
m_pRecordset = NULL;
} return TRUE;
}请大虾指点!!!