小弟用 vc6+ado+listcontrol+SQLSERVER 编程执行没发现错误,直接在查询分析器中SQL查询正常。但是listcontrol就是不能显示数据,我单步DEBUG也没发现错误.真地麻烦大神们了。。。
CoInitialize(NULL);
_ConnectionPtr pConn(__uuidof(Connection));
_RecordsetPtr pRst(__uuidof(Recordset));
//_CommandPtr pCmd(__uuidof(Command));
try
{
pConn->ConnectionString="Provider=SQLOLEDB.1;Password=aaaaaa;Persist Security Info=True;User ID=sa;Initial Catalog=forebase;Data Source=127.0.0.1";
pConn->Open("","","",adConnectUnspecified);
}
catch(_com_error e) //捕捉异常
{
return FALSE;
}
try
{
pRst=pConn->Execute("select * from forebase where 籍贯='赵' or 所在地域='王' or 专业='马' or 科目='牛' or 等级='胡' or 状态='黄'",NULL,adCmdText);
}
catch (_com_error e)
{
return FALSE;
}
try
{
int i=0;
while(!pRst->rsEOF)
{
m_l.SetItemText(i,0,(LPCTSTR)(_bstr_t)pRst->GetCollect("姓名"));
m_l.SetItemText(i,1,(LPCTSTR)(_bstr_t)pRst->GetCollect("籍贯"));
m_l.SetItemText(i,2,(LPCTSTR)(_bstr_t)pRst->GetCollect("所在地域"));
m_l.SetItemText(i,3,(LPCTSTR)(_bstr_t)pRst->GetCollect("专业"));
m_l.SetItemText(i,4,(LPCTSTR)(_bstr_t)pRst->GetCollect("科目"));
m_l.SetItemText(i,5,(LPCTSTR)(_bstr_t)pRst->GetCollect("等级"));
m_l.SetItemText(i,6,(LPCTSTR)(_bstr_t)pRst->GetCollect("状态"));
i++;
pRst->MoveNext();
}
}
catch (_com_error e)
{
return FALSE;
}
pRst->Close();
pConn->Close();
pRst.Release();
pConn.Release();
CoUninitialize();
------解决方案--------------------------------------------------------
连接字符串没有问题,一步一步debug一下吧,首先看看select 后pRst中有没有数据。