Kbase P103527: Is it possible to pass a dynamic proDataSet to a .Net Open Client
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  24/06/2008 |
|
Status: Verified
GOAL:
Is it possible to pass a dynamic ProDataSet to a .Net client
GOAL:
How to pass a dynamic ProDataSet to a .Net client
FACT(s) (Environment):
OpenEdge 10.x
Windows
FIX:
Yes, it is possible to pass a dynamic ProDataSet to a .Net client.
Below is an example against the 'sports2000' database allowing to pass a dynamic ProDataSet object to a C# client.
o 4GL code:
/* DynRelateDS.p
Overview of code:
The purpose of this demonstation code is to show one way of using 4GL dynamic coding
using the OpenEdge .NET Open Client.
Input parameters include the table sources, the keys for the sources, the relationships
between the sources. Examples of these values for the Sports2000 database include:
For Customer and Order tables:
pcSources = "Customer,Order"
pcKeys = "CustNum,OrderNum"
pcRelations = "CustNum,CustNum"
For Order and Orderline tables:
pcSources = "Order,OrderLine";
pcKeys = "OrderNum,LineNum";
pcRelations = "OrderNum,OrderNum";
Also as input parameters a range is specificed for the first table source. The range is
specified as greater than or equal to and less than or equal to using piGE and
piLE respectively.
The output parameter is the ProDataSet that was created and includes the two input tables
with the relation defined between them. The tables are populated based on the input range.
The 'OUTPUT TO', 'OUTPUT CLOSE', and DISPLAY statments are optional. They are included
in the example since they can be useful in quickly identifying some problems if the code
isn't working as expected. The output is created in C:\OpenEdge\wrk. This path
can be changed to a directory that exists on the system where the code is run.
*/
DEFINE INPUT PARAMETER pcSources AS CHARACTER NO-UNDO.
DEFINE INPUT PARAMETER pcKeys AS CHARACTER NO-UNDO.
DEFINE INPUT PARAMETER pcRelations AS CHARACTER NO-UNDO.
DEFINE INPUT PARAMETER piGE AS INTEGER NO-UNDO.
DEFINE INPUT PARAMETER piLE AS INTEGER NO-UNDO.
DEFINE OUTPUT PARAMETER DATASET-HANDLE phDataSet.
DEFINE VARIABLE iEntry AS INTEGER NO-UNDO.
DEFINE VARIABLE hDataSource AS HANDLE NO-UNDO.
DEFINE VARIABLE hBuffer AS HANDLE NO-UNDO.
DEFINE VARIABLE hQuery AS HANDLE NO-UNDO.
DEFINE VARIABLE hTable AS HANDLE NO-UNDO.
/*OUTPUT TO "C:\OpenEdge\WRK\DynRelateDSOUTT.txt".
DISPLAY "DynRelateDS.p" SKIP.*/
CREATE DATASET phDataSet.
tableLoop:
DO iEntry = 1 TO NUM-ENTRIES(pcSources):
CREATE TEMP-TABLE hTable.
hTable:CREATE-LIKE(ENTRY(iEntry, pcSources)).
hTable:TEMP-TABLE-PREPARE("Sport" + ENTRY(iEntry, pcSources)).
phDataSet:ADD-BUFFER(hTable:DEFAULT-BUFFER-HANDLE).
END.
DO iEntry = 1 TO NUM-ENTRIES(pcSources):
CREATE DATA-SOUR.CE hDataSource.
CREATE BUFFER hBuffer FOR TABLE ENTRY(iEntry, pcSources).
hDataSource:ADD-SOURCE-BUFFER(hBuffer, ENTRY(iEntry,pcKeys)).
phDataSet:GET-BUFFER-HANDLE(iEntry):ATTACH-DATA-SOURCE(hDataSource).
IF iEntry = 1 THEN
DO:
CREATE QUERY hQuery.
hQuery:ADD-BUFFER(hBuffer).
hQuery:QUERY-PREPARE("FOR EACH " + ENTRY(1, pcSources) +
" NO-LOCK WHERE " + ENTRY(1, pcKeys) + " GE " + STRING(piGE) +
" AND " + ENTRY(1, pcKeys) + " LE " + STRING(piLE)).
hDataSource:QUERY = hQuery.
END.
END.
phDataSet:ADD-RELATION(phDataSet:GET-BUFFER-HANDLE(1),
phDataSet:GET-BUFFER-HANDLE(2),
pcRelations).
phDataSet:FILL().
/*OUTPUT CLOSE. */
RETURN.
o Example of C# code:
int iLowRange = 1;
int iHighRange = 5;
string dynSources = "Customer,Order";
string dynKeys = "CustNum,OrderNum";
string dynRelate = "CustNum,CustNum";
System.Data.DataSet dsDynamic = new System.Data.DataSet();
// Assuming that the AppServer is called 'asbroker1' and the NameServer's port is 5162
YourProxy appobj = new YourProxy("AppServer://HostName:5162/asbroker1","","","");
// Call AppServer to get the data
appObj.DynRelateDS(dynSources, dynKeys, dynRelate, iLowRange, iHighRange, out dsDynamic);
// Assuming there is a dataGrid1 in the Form, set the dataGrid1's datasource
dataGrid1.DataSource = dsDynamic;
.