MFC之ADO
CoInitialize(NULL);
m_pConnection.CreateInstance(__uuidof(Connection));
m_pRecordset.CreateInstance(__uuidof(Recordset));
try
{
m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=Config.mdb","","",adModeUnknown);
}
catch(_com_error e)
{
AfxMessageBox("数据库连接失败,确认数据库Config.mdb是否在当前路径下!");
return FALSE;
}
以上部分没问题
try
{
m_pRecordset->Open("SELECT * FROM production",this->m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
if (!m_pRecordset->BOF)
{
m_pRecordset->MoveFirst();
}
else
{
AfxMessageBox("表内数据为空");
return 0;
}
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
以上部分没问题
然后我在另一个函数中再次open
sqlString.Format("select id, productionname, mode from produtcion where productionname=\'s\'",p.sProductionName);
//下面这个OPEN就出错了, 编译没错
m_pRecordset->Open((LPCTSTR)sqlString,this->m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
跟踪提示 CXX0017: Error: symbol "Open" not found
求解
[解决办法]
用这个软件先测试下你的SQL。
[解决办法]
可能是参数不对,你把sqlString.Format("select id, productionname, mode from produtcion where productionname=\'s\'",p.sProductionName);这句改成固定数据,比如:
sqlString.Format("select id, productionname, mode from produtcion where productionname='产品'");
是不是这应该改成这样:
sqlString.Format("select id, productionname, mode from produtcion where productionname='%s'"",p.sProductionName);
[解决办法]
sqlString.Format("select id, productionname, mode from produtcion where productionname='%s'",p.sProductionName);
[解决办法]
编译通不过还是?