请各位大侠指点呀,Ado+vc 出问题
我用vc+ado做小练习!出了警告信息,而且程序不能运行!
程序大致如下:
BOOL AdoTextDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
AfxOleInit();
m_connection.CreateInstance(__uuidof(Connection));
try
{
m_connection->Open("Provider=Microsoft.Jet.OLEDB.3.5.1;Data Source=Student1.mdb","","",adModeUnknown);///连接数据库
}
catch(_com_error e)
{
AfxMessageBox(e.ErrorMessage());
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void AdoTextDlg::OnOK()
{
// TODO: Add extra validation here
_variant_t vId,vName;
m_list.ResetContent();
m_recordset.CreateInstance(__uuidof(Recordset));
try
{
m_recordset->Open("select * from Student1",_variant_t((IDispatch *)m_connection,true),
adOpenStatic,adLockOptimistic,
adCmdText);
}
catch(_com_error e)
{
AfxMessageBox(e.ErrorMessage());
}
while(!m_recordset->adoEOF)
{
vId=m_recordset->GetCollect("stuid");
vName=m_recordset->GetCollect("stuname");
if(vId.vt!=NULL&&vName.vt!=NULL)
{
m_list.AddString((char*)_bstr_t(vName));
}
m_recordset->MoveNext();
}
if(m_reconnection->State) m_connection->Close();
m_recordset->Close();
m_recordset=NULL;
CDialog::OnOK();
}
初始化我也作了,智能指针我也定义了,警告信息如下:
warning C4146: unary minus operator applied to unsigned type, result still unsigned
双击时出现如下信息:
enum RecordCreateOptionsEnum
{
adCreateCollection = 8192,
adCreateStructDoc = -2147483648,
adCreateNonCollection = 0,
adOpenIfExists = 33554432,
adCreateOverwrite = 67108864,
adFailIfNotExists = -1
};