chMB()
是一个定义,MessageBoxA( 0, text, "title", MB_OK );
所以它显示文本,我可以看到结果。我的问题是以下代码:
CString szWow;
szWow.Format( "%u", idCandidate );
chMB( szWow );
const __int64 i64set = i64VoteAmount+1;
CString addvote;
addvote.Format( "UPDATE dbo.CONSULENTRIES set m_uVoteAmount = %u WHERE m_idCandidate = %u", i64set, idCandidate );
chMB( addvote );
chMB(szWow); 显示 5
尽管 chMB( addVote ) 显示: UPDATE dbo.CONSULENTRIES set m_uVoteAmount = 1 WHERE m_idCandidate = 0
为什么这种字符串格式的 idCandidate 0 ???O___O
如果你需要这里是完整的codez:
VOTEAPPL CConsulApplication::VoteForApplied( const u_long idVoter, const __int64 idCandidate )
{
if( idVoter && idCandidate )
{
/* Check if alredy voted */
CQuery* pQuery = new CQuery;
if( !pQuery->Connect( 3, DSN_NAME_CHARACTER01, DB_ADMIN_ID_CHARACTER01, DB_ADMIN_PASS_CHARACTER01 ) )
{
pQuery->DisConnect();
SAFE_DELETE( pQuery );
return VAPL_FAILURE;
}
CString szVoted;
szVoted.Format( "SELECT * FROM dbo.CONSULVOTE WHERE m_idVoter = %u", idVoter );
if( !pQuery->Exec( szVoted ) )
{
pQuery->DisConnect();
SAFE_DELETE( pQuery );
return VAPL_FAILURE;
}
pQuery->Fetch();
__int64 i64Voter = pQuery->GetInt64( "m_idVoter" );
if( i64Voter != 0 )
{
pQuery->DisConnect();
SAFE_DELETE( pQuery );
return VAPL_VOTED;
}
pQuery->DisConnect();
SAFE_DELETE( pQuery );
/* Get content and check if candidate exists */
CQuery* pQuery2 = new CQuery;
if( !pQuery2->Connect( 3, DSN_NAME_CHARACTER01, DB_ADMIN_ID_CHARACTER01, DB_ADMIN_PASS_CHARACTER01 ) )
{
pQuery2->DisConnect();
SAFE_DELETE( pQuery2 );
return VAPL_FAILURE;
}
CString szCandidate;
szCandidate.Format( "SELECT * FROM dbo.CONSULENTRIES WHERE m_idCandidate = %u", idCandidate );
if( !pQuery2->Exec( szCandidate ) )
{
pQuery2->DisConnect();
SAFE_DELETE( pQuery2 );
return VAPL_FAILURE;
}
pQuery2->Fetch();
__int64 i64Candidate = pQuery2->GetInt64( "m_idCandidate" );
__int64 i64VoteAmount = pQuery2->GetInt64( "m_uVoteAmount" );
if( i64Candidate != 0 )
{
/* Insert at database that this guy has voted */
CQuery* pInsertQuery = new CQuery;
if( !pInsertQuery->Connect( 3, DSN_NAME_CHARACTER01, DB_ADMIN_ID_CHARACTER01, DB_ADMIN_PASS_CHARACTER01 ) )
{
pInsertQuery->DisConnect();
SAFE_DELETE( pInsertQuery );
return VAPL_FAILURE;
}
CString szInsert;
szInsert.Format( "INSERT INTO dbo.CONSULVOTE values(%u,%u)", idVoter, idCandidate );
if( !pInsertQuery->Exec( szInsert ) )
{
pInsertQuery->DisConnect();
SAFE_DELETE( pInsertQuery );
return VAPL_FAILURE;
}
pInsertQuery->DisConnect();
SAFE_DELETE( pInsertQuery );
/* Update vote amount */
CQuery* pUpdate = new CQuery;
if( !pUpdate->Connect( 3, DSN_NAME_CHARACTER01, DB_ADMIN_ID_CHARACTER01, DB_ADMIN_PASS_CHARACTER01 ) )
{
pUpdate->DisConnect();
SAFE_DELETE( pUpdate );
return VAPL_FAILURE;
}
CString szWow;
szWow.Format( "%u", idCandidate );
chMB( szWow );
const __int64 i64set = i64VoteAmount+1;
CString addvote;
addvote.Format( "UPDATE dbo.CONSULENTRIES set m_uVoteAmount = %u WHERE m_idCandidate = %u", i64set, idCandidate );
chMB( addvote );
if( !pUpdate->Exec( addvote ) )
{
pUpdate->DisConnect();
SAFE_DELETE( pUpdate );
return VAPL_FAILURE;
}
pUpdate->DisConnect();
SAFE_DELETE( pUpdate );
return VAPL_SUCCESS;
}
pQuery2->DisConnect();
SAFE_DELETE( pQuery2 );
return VAPL_FAILURE;
}
return VAPL_FAILURE;
}