How do I read a dataset in Builder

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
mfbrowne
Posts: 13
Joined: Mon 15 Nov 2010 00:17

How do I read a dataset in Builder

Post by mfbrowne » Tue 08 Oct 2013 21:28

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

VladimirK
Devart Team
Posts: 16
Joined: Tue 24 Sep 2013 09:19

Re: How do I read a dataset in Builder

Post by VladimirK » Wed 09 Oct 2013 09:23

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();

mfbrowne
Posts: 13
Joined: Mon 15 Nov 2010 00:17

Re: How do I read a dataset in Builder

Post by mfbrowne » Thu 10 Oct 2013 14:28

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

VladimirK
Devart Team
Posts: 16
Joined: Tue 24 Sep 2013 09:19

Re: How do I read a dataset in Builder

Post by VladimirK » Fri 11 Oct 2013 13:24

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.

mfbrowne
Posts: 13
Joined: Mon 15 Nov 2010 00:17

Re: How do I read a dataset in Builder

Post by mfbrowne » Fri 11 Oct 2013 13:44

Vladimir,

I thought that might be the case but wanted to ask the question anyway to confirm my thoughts.

Thank you for answering

Mike

VladimirK
Devart Team
Posts: 16
Joined: Tue 24 Sep 2013 09:19

Re: How do I read a dataset in Builder

Post by VladimirK » Mon 14 Oct 2013 07:54

You are welcome. Feel free to contact us if you have any further questions about UniDAC.

Post Reply