Page 1 of 1
How do I read a dataset in Builder
Posted: Tue 08 Oct 2013 21:28
by mfbrowne
Hello,
Can someone assist me in reading a dataset using UniDac and cppBuilder. I have the following:
HstmtDatabase->Execute() ;
and I have 30 records returned based on an SQL statement I set in the HstmtDatabase. Now I would like to access these records from the dataset but can't seem to find out exactly how this is done.
Could someone provide me a snippit of code showing me how this is done.
Thanks
Mike
Re: How do I read a dataset in Builder
Posted: Wed 09 Oct 2013 09:23
by VladimirK
There are several SQL query types:
- data retrieving queries (for example, 'SELECT * FROM SomeTable');
- not data retrieving queries (for example, 'CREATE TABLE SomeTable');
The Execute method serves for queries, from which data retrieving is not demanded. To retrieve data from a query, you should use either the Open method (the Close method - for closing respectively) or the Active property (set it to True to open a query, and to False - to close the query). For example you can use
Code: Select all
UniQuery1->SQL->Text = "SELECT * FROM sometable";
UniQuery1->Open();
UniQuery1->First();
while (!UniQuery1->Eof){
ShowMessage(UniQuery1->FieldByName("id")->AsString);
UniQuery1->Next();
}
UniQuery1->Close();
Re: How do I read a dataset in Builder
Posted: Thu 10 Oct 2013 14:28
by mfbrowne
Thank you for the information.
To follow up on this, I have written a DLL that makes the calls and updates to my datbase. But if I perform a query and have multiple records returned, how would I return ( or the best way to return ) the full dataset to the calling program. For example I have 30 records returned by my query, I would like to pass that full dataset of 30 recoerds back to the calling program.
Thanks for any information, appreciate it.
Mike
Re: How do I read a dataset in Builder
Posted: Fri 11 Oct 2013 13:24
by VladimirK
We don't recommend to transfer TDataset between the dll and the application, as you will encounter a lot of problems while working with memory, allocation and freeing, working with components, class casting and debugging.
This applies not only to our components, but to any other components as well.
Re: How do I read a dataset in Builder
Posted: Fri 11 Oct 2013 13:44
by mfbrowne
Vladimir,
I thought that might be the case but wanted to ask the question anyway to confirm my thoughts.
Thank you for answering
Mike
Re: How do I read a dataset in Builder
Posted: Mon 14 Oct 2013 07:54
by VladimirK
You are welcome. Feel free to contact us if you have any further questions about UniDAC.