Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE

Using disconnected ADO.NET to bind data to DataGridView

Using disconnected ADO.NET to bind data to DataGridView

Problem:

I have data available in my COBOL program(data could be from sub-programs or data files etc.). How can I bind the data to DataGridView using disconnected ADO.NET?

Resolution:

You can use our OpenESQL technology to first declare the ADO datatable and dataset. Then use the EXEC ADO INITIALIZE statement to create the dataset and return a reference to the dataset. After the ADO dataset is created, you can use EXEC ADO INSERT statements to insert data to the datatable just like the traditional embeded EXEC SQL statements. The returned dataset object can be used in binding.

The sample code is below and the project is attached.

class-id DisconnectedADOSample.Form1 is partial

          inherits type System.Windows.Forms.Form.

working-storage section.

    exec sql include sqlca end-exec.

    exec ado

        declare emptb datatable

        ( empid int32

         ,empname string(10)

        )

    end-exec.

    exec ado

        declare empds dataset for emptb

    end-exec.        

method-id NEW.

procedure division.

    invoke self::InitializeComponent

    goback.

end method.

method-id button1_Click final private.

local-storage section.

01 ds type DataSet.

procedure division using by value sender as object e as type System.EventArgs.

    set ds to self::createdataset

    set dataGridView1::DataSource to ds

    set dataGridView1::DataMember to "emptb"

end method.

method-id createdataset.

local-storage section.

01 obj object.

procedure division returning myds as type DataSet.

    exec ado

        using empds initialize dataset returning :obj

    end-exec

    exec ado

        insert into emptb (empid, empname)

                   values (1, 'Evan')

    end-exec

    exec ado

        insert into emptb (empid, empname)

                   values (2, 'John')

    end-exec 

    exec ado

        accept changes for emptb

    end-exec   

    set myds to obj as type DataSet      

end method.

end class.


8321.DisconnectedADOSample.zip

DISCLAIMER:

Some content on Community Tips & Information pages is not officially supported by Micro Focus. Please refer to our Terms of Use for more detail.
Top Contributors
Version history
Revision #:
1 of 1
Last update:
‎2015-05-21 14:32
Updated by:
 
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.