Ask Experts Questions for FREE Help !
Ask
    Tsholofelo's Avatar
    Tsholofelo Posts: 6, Reputation: 1
    New Member
     
    #1

    May 10, 2007, 04:49 AM
    C++ and mysql
    I want a query that can select all names in a table and write it in sequential form in a listbox of a form in C++.the connection is well established and communication between my system and my datbase is working fine.

    here is the statement I used:

    requestName = SELECT SystemName FROM System;
    my_query->SQL->Add(requestName);
    my_query->Open();
    systemRequested = Form1->Bugs_Query->FieldByName("SystemName")->AsString;
    listbox1->Items->Add(systemRequested );

    it is working fine except that it only gives the first systemName, but I need the whole list. I realised that mysql counts rows from 0 to last-1. I tried for loop but it gives errors:

    for(int x=0;x!=-1;x++)
    {
    requestName = SELECT SystemName FROM System;
    my_query->SQL->Add(requestName);
    my_query->Open();
    systemRequested = Form1->Bugs_Query->FieldByName("SystemName")->AsString;
    listbox1->Items->Add(systemRequested );
    }

    I tried putting vlue of x everywhere it is possible but none seem to work, does anybody know how I can do this.

    please help it is very urgent.

    thanks (tsholo)
    Nosnosna's Avatar
    Nosnosna Posts: 434, Reputation: 103
    Full Member
     
    #2

    May 10, 2007, 01:50 PM
    You will need to continue using the same connection, query, and reader. In your for() loop, you restart the query each iteration... this method will return the first row every time it's run.

    Also, you cannot use control variables the way you have: x will, by inspection, never reach the termination condition without generating an overflow exception.

    What method are you using to connect your program to the database? Without knowing the datatypes being used, it's impossible to figure out how to fix it.
    Tsholofelo's Avatar
    Tsholofelo Posts: 6, Reputation: 1
    New Member
     
    #3

    May 14, 2007, 01:50 AM
    actually there is a way of doing it and I did figure it out but anyway thanks for trying to help. Just in case u might need this. A tquery component of C++ has a property RowAffected, al u have 2 do is test if the rows affeted are > 0 then keep on reading for as long as there is something in the database

    while( TQuery->RowsAffected > 0 )
    {
    systemRequested = Form1->TQuery->FieldByName("SystemName")->AsString;
    TQuery->Next();





    }

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Php5 mysql hosting [ 11 Answers ]

I am looking to hopefully move my web page off my home server (when its complete) to a more capable hosting solution. All I really require of the server is that it supports PHP5 and some fairly recent version of MySQL (although I'm not particularly picky about the MySQL part). Storage and max...

Connecting to MySQL with PHP on Apache 2.2 [ 2 Answers ]

Hello all, Just a little background on my system. I am running Windows XP Pro SP2. Firewall is disabled. Running Apache 2.2, PHP5 and MySQL server 5.1. I am trying to simple interface with my MySQL database using a webpage running PHP. I have tried using the mysql_connect(host, name,...


View more questions Search