c++sqlfirebirddbexpressc++builder-xe6

How can I get the result of a request after executing the request using c++ builder XE6 and Firebird?


After connecting to a Firebird database with C++ builder, I cannot get a result from a simple select request.

I have some confusion about a lot of members of classes:

void __fastcall TForm2::btn1Click(TObject *Sender)
{  TSQLConnection   co = new TSQLConnection(this); 
   Base_Firebird *fb = new Base_Firebird()  ;
   bool  bl = fb->Connecter(co);   
   String sqlstring = "select nom_action from T_ACTION where CLE_ACTION=6 ";     
   if (bl)     
      TSQLQuery *req = new TSQLQuery(NULL) ;    
   req->SQLConnection = co ;
   req->SQL->Add(sqlstring);
   req->Open() ;
  }

My problem is here after opening the TSQLQuery, I don't know how I can get the result and execute the command.


Solution

  • Read Embarcadero's documentation. There are whole chapters on how to work the SQL components you are using, including:

    How To Perform Database Procedures

    Navigating Datasets

    Using dbExpress

    Using dbExpress Components Index

    Using TSQLQuery

    Data.SqlExpr.TSQLQuery

    For example:

    void __fastcall TForm2::btn1Click(TObject *Sender)
    {
        TSQLConnection *co = new TSQLConnection(NULL); 
        Base_Firebird *fb = new Base_Firebird();
        if (fb->Connecter(co))
        {
            TSQLQuery *req = new TSQLQuery(NULL);
            req->SQLConnection = co;
            req->SQL->Text = "select nom_action from T_ACTION where CLE_ACTION=6";
            req->Open();
            while (!req->Eof)
            {
                // use req->Fields as needed...
                req->Next();
            }
            delete req;
        }
        delete fb;
        delete co; 
    }