Ask Experts Questions for FREE Help!
  Advanced
Register  |  Log in  
   Ask    
 Answer  
  Help  

Ask QuestionsprogressAnswer QuestionsprogressBuild ReputationprogressBecome an Expert
 
Free Answers in 3 Easy Steps

Register Now
3 Steps

At Ask Me Help Desk you can ask questions in any topic and have them answered for free by our experts. To ask questions or participate in answering them you must register for a free account. By registering you will be able to:
  • Get free answers from experts in any of our 300+ topics.
  • Accept money for answers that you provide.
  • Communicate privately with other members (PM).
  • See fewer ads.

Home > Computers & Technology > Programming > Compiled Languages > C++   »   C++ and mysql

 
Question Tools Search this Question Display Modes
Question
 
 
#1  
Old May 10, 2007, 03:49 AM
Tsholofelo
New Member
Tsholofelo is offline
 
Join Date: Apr 2007
Posts: 8
Tsholofelo See this member's comment history on his/her Profile page.
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)

Reply With Quote
 
     

Answers
 
 
Old May 10, 2007, 12:50 PM   #2  
Nosnosna
Senior Member
Nosnosna is offline
 
Join Date: Jan 2007
Location: East bumble, TN
Posts: 434
Nosnosna See this member's comment history on his/her Profile page.
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.
  Reply With Quote
 
     
 
 
Old May 14, 2007, 12:50 AM   #3  
Tsholofelo
New Member
Tsholofelo is offline
 
Join Date: Apr 2007
Posts: 8
Tsholofelo See this member's comment history on his/her Profile page.
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();





}
  Reply With Quote
 
     


Question Tools Search this Question
Search this Question:

Advanced Search
Display Modes

 
Similar Sponsors

Similar Questions
Question Asker Topic Answers Last Post
PHP5 MySQL Hosting Ademan Hosting 11 May 6, 2008 12:38 PM
Connecting to MySQL with PHP on Apache 2.2 sypher373 PHP 2 Jan 11, 2008 02:48 PM
MySQL with C++ Tsholofelo MySQL 0 May 10, 2007 03:15 AM




Copyright ©2003 - 2007, Ask Me Help Desk.
All times are GMT -8. The time now is 02:44 PM.

Content Relevant URLs by vBSEO 3.0.0 RC6 © 2006, Crawlability, Inc.