ADO连接ACESS错误:IDispatch error #3149是什么意思?
我编写的程序,ADO连接ACESS错误:IDispatch error #3149到底 什么意思?大家请帮帮忙,谢谢
有兴趣的可以参见代码如下:
程序代码:BOOL CQueryDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
CString strSql;//query command
m_listbook.SetExtendedStyle (LVS_EX_TRACKSELECT|LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);//有表格的显示
m_listbook.InsertColumn (0,"商品码",LVCFMT_CENTER,70);
m_listbook.InsertColumn (1,"类型",LVCFMT_CENTER,170);
m_listbook.InsertColumn (2,"书名",LVCFMT_CENTER,60);
m_listbook.InsertColumn (3,"作者",LVCFMT_CENTER,60);
m_listbook.InsertColumn (4,"版本号",LVCFMT_CENTER,260);
m_listbook.InsertColumn (5,"出版时间",LVCFMT_CENTER,70);
m_listbook.InsertColumn (6,"出版社",LVCFMT_CENTER,170);
m_listbook.InsertColumn (7,"库存数量",LVCFMT_CENTER,60);
//m_listbook.InsertColumn (3,"卖出数量",LVCFMT_CENTER,60);
m_listbook.InsertColumn (8,"打折",LVCFMT_CENTER,260);
//m_listbook.InsertColumn (0,"进货日期",LVCFMT_CENTER,70);
//m_listbook.InsertColumn (1,"卖出日期",LVCFMT_CENTER,170);
//m_listbook.InsertColumn (2,"进货价格",LVCFMT_CENTER,60);
m_listbook.InsertColumn (9,"销售价格",LVCFMT_CENTER,60);
m_listbook.InsertColumn (10,"其他",LVCFMT_CENTER,260);
//connect to the database
try
{
if (!m_pConnection.CreateInstance(__uuidof(Connection)))
m_pConnection->Open("Provider=Microsoft.JET.OLEDB.4.0;Data Source=.\data\sybsData.mdb","admin","admin",adModeUnknown);
}
catch (_com_error e)
{
CString errormessage;
errormessage.Format ("连接数据库失败!\r\n错误信息:%s",e.ErrorMessage ());
AfxMessageBox (errormessage);
return FALSE;
}
try
{
//determine the result set object
m_pRecordset.CreateInstance(__uuidof(Recordset));
strSql="SELECT * FROM bookInfo";
//execute the sql command
m_pRecordset->Open (_variant_t(strSql),m_pConnection.GetInterfacePtr (),
adOpenStatic,adLockOptimistic,adCmdText);
//_variant_t vName,vPsw;
int nIndex=0;
//read result record
while (!m_pRecordset->adoEOF)
{
m_listbook.InsertItem (nIndex,(_bstr_t)(m_pRecordset->GetCollect ("商品码")));
m_listbook.SetItemText (nIndex,1,(_bstr_t)(m_pRecordset->GetCollect ("类型")));
m_listbook.SetItemText (nIndex,2,(_bstr_t)(m_pRecordset->GetCollect ("书名")));
m_listbook.SetItemText (nIndex,3,(_bstr_t)(m_pRecordset->GetCollect ("作者")));
m_listbook.SetItemText (nIndex,4,(_bstr_t)(m_pRecordset->GetCollect ("版本号")));
m_listbook.SetItemText (nIndex,5,(_bstr_t)(m_pRecordset->GetCollect ("出版时间")));
m_listbook.SetItemText (nIndex,6,(_bstr_t)(m_pRecordset->GetCollect ("出版社")));
m_listbook.SetItemText (nIndex,7,(_bstr_t)(m_pRecordset->GetCollect ("库存数量")));
//m_listbook.SetItemText (nIndex,4,(_bstr_t)(m_pRecordset->GetCollect ("卖出数量")));
m_listbook.SetItemText (nIndex,8,(_bstr_t)(m_pRecordset->GetCollect ("打折")));
//m_listbook.SetItemText (nIndex,2,(_bstr_t)(m_pRecordset->GetCollect ("进货日期")));
//m_listbook.SetItemText (nIndex,3,(_bstr_t)(m_pRecordset->GetCollect ("卖出日期")));
//m_listbook.SetItemText (nIndex,4,(_bstr_t)(m_pRecordset->GetCollect ("进货价格")));
m_listbook.SetItemText (nIndex,9,(_bstr_t)(m_pRecordset->GetCollect ("销售价格")));
m_listbook.SetItemText (nIndex,10,(_bstr_t)(m_pRecordset->GetCollect ("其他")));
//m_listbook.InsertColumn (0,"商品码",LVCFMT_CENTER,70);
//m_listbook.InsertColumn (1,"类型",LVCFMT_CENTER,170);
//m_listbook.InsertColumn (2,"书名",LVCFMT_CENTER,60);
//m_listbook.InsertColumn (3,"作者",LVCFMT_CENTER,60);
//m_listbook.InsertColumn (4,"版本号",LVCFMT_CENTER,260);
//m_listbook.InsertColumn (5,"出版时间",LVCFMT_CENTER,70);
//m_listbook.InsertColumn (6,"出版社",LVCFMT_CENTER,170);
//m_listbook.InsertColumn (7,"库存数量",LVCFMT_CENTER,60);
////m_listbook.InsertColumn (3,"卖出数量",LVCFMT_CENTER,60);
//m_listbook.InsertColumn (8,"打折",LVCFMT_CENTER,260);
////m_listbook.InsertColumn (0,"进货日期",LVCFMT_CENTER,70);
////m_listbook.InsertColumn (1,"卖出日期",LVCFMT_CENTER,170);
////m_listbook.InsertColumn (2,"进货价格",LVCFMT_CENTER,60);
//m_listbook.InsertColumn (9,"销售价格",LVCFMT_CENTER,60);
//m_listbook.InsertColumn (10,"其他",LVCFMT_CENTER,260);
nIndex++;
m_pRecordset->MoveNext ();
}
m_pRecordset->Close ();
}
catch (_com_error e)
{
CString errormessage;
errormessage.Format ("连接数据库失败!\r\n错误信息:%s",e.ErrorMessage ());
AfxMessageBox (errormessage);
return FALSE;
}/**/
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}






