ADO连接数据库成功.
m_pset为_RecordsetPtr对象
m_pConnection为_ConnectionPtr对象
m_kahao是一个IDC_EDIT控件.
代码如下:
m_pset->Open("select * from renzl where 卡号=m_kahao",_variant_t((IDispatch*)m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);主要是"select * from renzl where 卡号=m_kahao"这句SQL语句
在c#里可以"select * from renzl where 卡号='"+m_kahao+"'"
C++里不行,请问各位老师怎么解决?我还用了:
CString strSQL;
strSQL.Format("select * from renzl where 卡号='%s'",m_kahao);
然后把strSQL传入Open还是不行,说第一个参数错误!
m_pset为_RecordsetPtr对象
m_pConnection为_ConnectionPtr对象
m_kahao是一个IDC_EDIT控件.
代码如下:
m_pset->Open("select * from renzl where 卡号=m_kahao",_variant_t((IDispatch*)m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);主要是"select * from renzl where 卡号=m_kahao"这句SQL语句
在c#里可以"select * from renzl where 卡号='"+m_kahao+"'"
C++里不行,请问各位老师怎么解决?我还用了:
CString strSQL;
strSQL.Format("select * from renzl where 卡号='%s'",m_kahao);
然后把strSQL传入Open还是不行,说第一个参数错误!
改为strSQL.Format("select * from renzl where 卡号=\'%s\'",m_kahao);
CString strSQL;
strSQL.Format("select * from renzl where 卡号='%s'",m_kahao);
m_pset->Open(strSQL,_variant_t((IDispatch*)m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
无论strSQL改成什么都提示:
error C2664: 'Open' : cannot convert parameter 1 from 'class CString' to 'const class _variant_t &'
Reason: cannot convert from 'class CString' to 'const class _variant_t'
No constructor could take the source type, or constructor overload resolution was ambiguous
// m_pRecordset->Open(_variant_t("mytable"),
// _variant_t((IDispatch *)m_pConnection,true), adOpenKeyset,
// adLockOptimistic, adCmdTable);
// }
// catch (_com_error &e)
// {
// ::MessageBox(NULL,"该表不存在。","提示",MB_OK │ MB_ICONWARNING);
// }
m_pRecordset->Open(_variant_t(pStr ),
_bstr_t 和 _variant_t一般和ADO配套使用