m_pUserSet->Open(_variant_t(sql),
theApp.m_pConnection.GetInterfacePtr( ),
adOpenDynamic,
adLockOptimistic,
adCmdText
);
其他的和一般的连接一样,可惜就是连不上,错误信息是“无效指针”,不知道是怎么搞得。
BOOL Cado2Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
CString strConn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Temp\\testdb.mdb";
bstr_t bstrConn=strConn.AllocSysString ();
pConn.CreateInstance (__uuidof(Connection));
pConn->Open (bstrConn,"","",-1);
pRst.CreateInstance (__uuidof(Recordset));
pRst->Open ("Select * from grade",pConn.GetInterfacePtr (),adOpenDynamic,adLockOptimistic,adCmdText);
_variant_t varName;
TRY
{
pRst->MoveFirst();
varName=pRst->GetCollect("Name");
//((CListBox *)GetDlgItem(IDC_EDIT1))->AddString(pRst->GetCollect("Name"));
if(varName.vt!=VT_NULL)
m_Name=(char*)_bstr_t(varName);
}
CATCH_ALL(e)
AfxMessageBox("初始化失败");
END_CATCH_ALL
UpdateData(FALSE);
void Cado2Dlg::OnBnClickedButton1()
{
// TODO: 在此添加控件通知处理程序代码
while(!pRst->adoEOF)
{
pRst->MoveNext();
CString str;
str=pRst->GetCollect("Name");
MessageBox(str);
}
}
看看可以不:)