|
各位大大,快帮帮小弟吧,对于数据库我是想把它写成一个DLL的形式:
CADODatabase::CADODatabase()
{
::CoInitialize(0);
m_pConnect.CreateInstance(__uuidof(Connection));
m_pConnect->ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI; \
Persist Security Info=False;Initial Catalog=NetDisk;Data Source=127.0.0.1";
m_pConnect->Open("", "", "", -1);
}
CADODatabase::~CADODatabase()
{
m_pConnect->Close();
m_pConnect.Release();
::CoUninitialize();
}
// Judge if the user is legal.
bool CADODatabase::JudgeLogIn(CString strUsername, CString strPassword, CString strTableName)
{
if(FAILED(m_pRecordset.CreateInstance(__uuidof(Recordset))))
{
return false;
}
CString strQuery;
strQuery.Format(_T("select * from %s where %s.Username = \'%s\' AND \
%s.Password = \'%s\'"), strTableName, strTableName,
strUsername, strTableName, strPassword);
try
{
m_pRecordset->Open(_bstr_t(strQuery),
_variant_t((IDispatch *)m_pConnect,true), adOpenStatic,
adLockOptimistic, adCmdTable);
m_pRecordset->MoveFirst();
if (m_pRecordset->adoEOF == VARIANT_FALSE)
{
return true;
}
return false;
}
catch (_com_error &e)
{
AfxMessageBox(e.Description());
}
m_pRecordset->Close();
m_pRecordset.Release();
return false;
}
每每在m_pRecordset->Open处就会抛出异常,然后会得到错误描述:"在关键字'select'附近有语法错误",但是当我单步跟踪到这一步的时候,把strQuery的值COPY到查询分析器里面,然后执行却没错....无语了....请问是为什么呢? |
|