|
Everyone big, quickly help the younger, for the database I want to write it as a 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;
}
I always throw an exception at m_pRecordset-> Open, and then I get an error description: "There is a syntax error near the keyword 'select'", but when I stepped into this step, COPY the value of strQuery to Query the analyzer, and then executed it ... but speechless ... Why is that? |
|