4,012
社区成员
发帖
与我相关
我的任务
分享
_ConnectionPtr m_pConnection;
_RecordsetPtr m_pRecordset;
_CommandPtr m_pCommand;
m_pConnection.CreateInstance(__uuidof(Connection));
m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Data//Tally.mdb","","",adModeUnknown);
m_pCommand.CreateInstance(__uuidof(Command));
m_pCommand->ActiveConnection = m_pConnection; /* 将库连接赋于它 */
m_pCommand->CommandText = "SELECT * FROM TallyUser"; /* SQL语句 */
m_pCommand->CommandType=adCmdText;
m_pCommand->Parameters->Refresh();
m_pRecordset = m_pCommand->Execute(NULL, NULL, adCmdUnknown); /* 执行SQL语句,返回记录集 */
_RecordsetPtr m_pRecordset;
m_pRecordset.CreateInstance(__uuidof(Recordset));
m_pRecordset->CursorLocation = adUseClient;
_ConnectionPtr m_pConnection;
_RecordsetPtr m_pRecordset;
_CommandPtr m_pCommand;
if (!AfxOleInit())
{
AfxMessageBox("OLE初始化出错!");
}
m_pConnection.CreateInstance(__uuidof(Connection));
m_pRecordset->CursorLocation = adUseClient;
m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Data//Tally.mdb","","",adModeUnknown);
m_pCommand.CreateInstance(__uuidof(Command));
m_pCommand->ActiveConnection = m_pConnection; /* 将库连接赋于它 */
m_pCommand->CommandText = "SELECT * FROM TallyUser"; /* SQL语句 */
m_pCommand->CommandType=adCmdText;
m_pCommand->Parameters->Refresh();
m_pRecordset = m_pCommand->Execute(NULL, NULL, adCmdUnknown); /* 执行SQL语句,返回记录集 */
try
{
CoInitialize(NULL);
_ConnectionPtr pConn(__uuidof(Connection));
_RecordsetPtr pRst(__uuidof(Recordset));
/*pConn->ConnectionString="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;PassWord=123;Server=.;Initial Catalog=WirelessCare";*/
pConn->ConnectionString=((_bstr_t)ConfigConnString);
pConn->Open("","","",adConnectUnspecified);
pRst=pConn->Execute("select * from City",NULL,adCmdText);
while(!pRst->rsEOF)
{
int iPos=m_MyList->InsertItem(0,(_bstr_t)pRst->GetCollect("id"));
m_MyList->SetItemText(iPos,1,(_bstr_t)pRst->GetCollect("name"));
m_MyList->SetItemText(iPos,2,(_bstr_t)pRst->GetCollect("provinceid"));
pRst->MoveNext();
}
pRst->Close();
pConn->Close();
pRst.Release();
pConn.Release();
CoUninitialize();
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
}
m_pRecordset->RecordCount==-1;
//要想使这个起作用,起码要加上
m_pRecordset->CursorLocation=adUseClient; //使用客户端游标,ADO默认是服务器端游标。
//很少用这个判断数据集是否有值
if(m_pRecordset->EOF && m_pRecordset->BOF) //记录集指针同时为记录头和记录尾,则没有数据。