-3

chMB() is a define to MessageBoxA( 0, text, "title", MB_OK );so it displays the text and I can see results. My problem is with the following codez:

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 ); displayes 5

althought chMB( addVote ) displayes: UPDATE dbo.CONSULENTRIES set m_uVoteAmount = 1 WHERE m_idCandidate = 0

why is idCandidate 0 on this string format??? O___O

in case you need here is teh full 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;

}

Bill Lynch
  • 80,138
  • 16
  • 128
  • 173
Vinícius
  • 15,498
  • 3
  • 29
  • 53
  • why downvote? can someone help me, i need an answer not downvotes .__. – Vinícius Aug 20 '12 at 06:56
  • 4
    I'm not responsible for the downvote, but things like "in case you need here is teh full codez:" make it sound like you are five. – Bill Lynch Aug 20 '12 at 06:57
  • Let me see: Giant-wall-o-code, virtually undecipherable problem, no way I can reproduce, no idea of what you've tried already – Puppy Aug 20 '12 at 06:58
  • yeah cause after 8 years of programming talking like a professional is what is more important – Vinícius Aug 20 '12 at 06:58
  • Is idCandidate a very large integer (not fitting 32 bits)? Because you use %u to output it in the CString, and that is for unsigned int. For unsigned long, you should use %ul. – Lyubomir Vasilev Aug 20 '12 at 06:58
  • `%ul` causes causes it to display `0l` instead of `0`. thanks for answer althought! – Vinícius Aug 20 '12 at 07:01
  • @sharth (off-topic, sorry) What does "you are five" mean? Is it an idiom like "you are high"? – anatolyg Aug 20 '12 at 07:10
  • It's not `"%ul"`, it should be `"%lu"`. The `l` is a size modifier and the `u` is the type. See the [manual page](http://msdn.microsoft.com/en-us/library/56e442dc%28v=vs.100%29.aspx). And I agree with sharth, please write proper English. – Some programmer dude Aug 20 '12 at 07:10
  • @anatolyg: I was being relatively literal. (I'm assuming you're a non-native english speaker). I'm essentially saying that his choice of language (in this case, slang), makes his post seem quite unprofessional and gives an appearance that he doesn't really care about it. I said like 5 (which is a bit extreme), because I associate spelling like "codez", "teh", and "O__O" with a younger (pre-teenager) audience. – Bill Lynch Aug 20 '12 at 07:19

1 Answers1

3

The problem is here:

addvote.Format( "UPDATE dbo.CONSULENTRIES set m_uVoteAmount = %u WHERE m_idCandidate = %u", i64set, idCandidate );

The format string contains %u while the variable after the format string (i64set) is of a wrong type (__int64).

Try changing the type (%u corresponds to type unsigned int) or the format specifier:

addvote.Format( "UPDATE dbo.CONSULENTRIES set m_uVoteAmount = %I64d WHERE m_idCandidate = %u", i64set, idCandidate );
anatolyg
  • 26,506
  • 9
  • 60
  • 134