在MFC里用ADO连接数据库
下面这一句是测试用的,是正确的:
m_pAdoRecordset->Open("select UserName from OJUser where UserName = 'admin'",_variant_t((IDispatch *)m_pAdoConnect,true),adOpenDynamic,adLockOptimistic,adCmdText);
但是因为我要根据输入值来获取查询语句,所以我是这么写的:
CString strSQL;
strSQL.Format(_T("select UserName from OJUser where UserName = ‘%s’"),m_Username);
测试的时候这一句也没问题,获得的strSQL也是正确的SQL语句
open方法我是这么写的:
m_pAdoRecordset->Open((_variant_t)strSQL,_variant_t(m_pAdoConnect,true),adOpenStatic,adLockOptimistic,adCmdText);
这里运行的时候就会发生中断,中断文件在msado15.tli
中断代码在
inline HRESULT Recordset15::Open ( const _variant_t & Source, const _variant_t & ActiveConnection, enum CursorTypeEnum CursorType, enum LockTypeEnum LockType, long Options ) {
HRESULT _hr = raw_Open(Source, ActiveConnection, CursorType, LockType, Options);
if (FAILED(_hr)) _com_issue_errorex(_hr, this, __uuidof(this));
return _hr;
}
的return处
继续执行,下一次中断在
inline FieldPtr Fields15::GetItem ( const _variant_t & Index ) {
struct Field * _result = 0;
HRESULT _hr = get_Item(Index, &_result);
if (FAILED(_hr)) _com_issue_errorex(_hr, this, __uuidof(this));
return FieldPtr(_result, false);
}
的return处
最后中断在
inline _variant_t Field20::GetValue ( ) {
VARIANT _result;
VariantInit(&_result);
HRESULT _hr = get_Value(&_result);
if (FAILED(_hr)) _com_issue_errorex(_hr, this, __uuidof(this));
return _variant_t(_result, false);
}
的 HRESULT _hr = get_Value(&_result);
我想知道这是为什么?另外我用CString保存动态SQL语句后 open函数该怎么用?
本人学生,懂的不多,希望各位大大说的详细点,谢谢!