Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   C++ (https://www.askmehelpdesk.com/forumdisplay.php?f=439)
-   -   C++ and mysql (https://www.askmehelpdesk.com/showthread.php?t=91118)

  • May 10, 2007, 04:49 AM
    Tsholofelo
    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)
  • May 10, 2007, 01:50 PM
    Nosnosna
    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.
  • May 14, 2007, 01:50 AM
    Tsholofelo
    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();





    }

  • All times are GMT -7. The time now is 12:31 AM.