The last few months have had me focused on an internal project which involves multiple pieces, some of which are Micro Focus products, while others are from partners such as HP, LRS, Syncsort, Microsoft and CA.
And as such, I haven't had much time to dig into using my new favorite tool, Visual COBOL. That's left me sad *smile*. To fix this, I spent part of my weekend writing code. It sure beat raking leaves! (Ummm... I'll get to it next weekend I promise dear).
One of the things I figured out was how to create an ADO.Net datatable, add fields to it, populate it with data, and tie it to a DataGrid. It's pretty easy actually.
First thing you do is define a variable in working storage that can hold the definition of the table.
Then in my program I create a new instance of the table and store it in this variable.
And then I added a column to the ADO.Net datatable by first defining a variable in Working Storage that could hold the definition of a column:
And then doing the add like so:
After that, it was just a matter of setting the various properties of the column:
And adding it to my datatable.
Once I had the table defined, I linked the datagrid control I had placed on my Winform to it.
Now that the data table has been defined, it is just a matter of adding some data to it. To do this, I had to first create a new row in the datatable.
And then once that was done, I inserted data into that row matching its definition:
The only tough part was figuring out the syntax of adding a row to the table. In VB.Net, the statement would have been:
Trow = Tbl.NewRow()
But as you can see, in Visual COBOL, I had to first set the data type of the field and then add it to the table. What's an extra statement among friends right? *smile*
The last set statement above uses the Now method of System.DateTime and stores it in the column I created. The "ToShortDateString" at the end of it allow me to choose the format of the date string being stored into the column. I could have just as easily accepted the current-date from the system clock and placed it in there. But I thought I would try the .Net method instead.
Fairly simple. Once I figured all this out, it didn't take long to expand on things and create something I could toy around with...
Yes, I know it isn't that impressive, but I now know how to create an ADO.Net data table, populate it and link it to a datagrid. And so do you by the way *wink*.
And I'm betting neither one of us knew how to do it before you read this.
See, I can learn new tricks *smile*
-
No comments:
Post a Comment