Page 1 of 1

Using a SQL command on a Virtual Table

Posted: Fri 25 Mar 2011 10:30
by FrankT
Hi all,

I am using the Virtual Table Component from SQL Server DAC for Delphi / C++ Builder 2010 and I would like to use a Select statement on the data in that table, something like Select * from VirtualTable1 WHERE ID = 1. Since there is no connection to an external database, none of the standard SQL Query components will work with it.

Is there a way to use standard SQL commands with or without a SQL Query Component on the data in this Virtual Table and if so can someone Please explain how to do it.

Thank You,

Frank

Posted: Mon 28 Mar 2011 08:51
by AndreyZ
Hello,

You cannot use SQL queries for the TVirtualTable component. You can use the TCRBatchMove component to extract data from the TVirtualTable component in the following way:

Code: Select all

VirtualTable1.AddField('id', ftInteger);
VirtualTable1.AddField('name', ftString, 10);
VirtualTable1.Open;
VirtualTable1.AppendRecord([1, 'n1']);
VirtualTable1.AppendRecord([1, 'n2']);
VirtualTable1.AppendRecord([2, 'n3']);
VirtualTable1.AppendRecord([2, 'n4']);
VirtualTable1.AppendRecord([2, 'n5']);
VirtualTable1.Filter := 'id=2';
VirtualTable1.Filtered := True;

VirtualTable2.AddField('id', ftInteger);
VirtualTable2.AddField('name', ftString, 10);
VirtualTable2.Open;
CRBatchMove.Source := VirtualTable1;
CRBatchMove.Destination := VirtualTable2;
CRBatchMove.Execute;
VirtualTable1.Filtered := False;
You can use any dataset descendant component instead of VirtualTable2 to unload data to it from the TVirtualTable component.