Search This Blog

Sunday, October 10, 2010

ASP.Net, ADO.Net and COBOL - The Right Tools for the Job

Hey folks,

In working on learning how to write a web application using COBOL, I thought it would be interesting to understand how to retrieve a BLOB (binary large object) using ADO.Net and display it back to the user.

So, armed with a downloaded copy of the AdventureWorks database from Microsoft's website, I set about to create an ASP.Net page and its corresponding "code behind" page (out of COBOL of course) to do just that. 


First off, you'll see from the ASP.Net page in the image above that I'm populating a drop down list box with data from one of the tables in the database.  Once the user selects a row from the list, the code behind page launches the "Fetch_ProductImage" method defined within my COBOL program (to see the complete images you may have to click on them to make them full screen).


The image above shows the various objects I had to define using some of the "new" data types I mentioned in an earlier post to this site.  Addittionally, you'll see that I define objects based on the ADO.Net class.  How I use them is shown below in the  method "Fetch_ProductImage".  This is used to grab the image stored within the BLOB field for the selected item:


Once selected the image is displayed to the user via the web browser.  Pretty slick huh?

It's much like using cursors with traditional SQL, with many of the same steps.  In traditional SQL, you define the cursor, open the cursor, read the row(s), then close the cursor.  Similar thing with the data reader.  You define the statement you wish to execute against the table, open the data reader, load the data reader with the rows you wanted, read the row(s) from the data reader, close the connection.  Very similar processes.

One interesting difference I've found is that with a data reader, the rows are stored as "read only".  With traditional SQL you can choose to update the rows contained within the cursor.  But within a data reader, the data can't be modified.  And as I believe is true with a cursor, you can only read forward with the data reader.  Once you have read the row, the previous row is no longer available to you.

There are several other interesting things you can do with ADO.Net.  Just to give you an idea... Everything above was based on examples in the first 50 pages from a 585 book I bought on ADO.Net.  Yes it was written for a VB.Net developer, but I was able to translate it from gibberish into COBOL easily enough *grin*.

Overall it wasn't too difficult. Yes, I know I didn't go into details on how to do all the steps involved with the web form portion of this.  That was because I figure that was the easier part and you too can pick that up from a good book on building ASP.Net web pages.  As I mentioned in a previous post, I've been working from Imar's book "Beginning ASP.Net 4 in C# and VB".  As to the rest, it is all shown above in the COBOL example.  There's surprisingly not that much to it huh?

I hope this was of value for you.   Drop me a note if you have any questions or comments.  I'd love to hear from you!

1 comment: