A general question on how to "FILL A STRUCTURE with DATA ON WIN FORM LOAD EVENT", with some detail code included.  I am new to VB2005.NET.  I have created a FORM and figured out how to LOAD a DATAGRID CONTROL from an MS ACCESS Table.  Most of the code to do this was auto-generated and all I did was tweak control/object properties or Event Handlers.  I got what I wanted, a DATABOUND GRID CONTROL to AUTOFILL on a WIN FORM.

What I really want to do now is to cycle thru the MS ACCESS TABLE DATA and read each ROW ELEMENT in to a RECORD STRUCTURE and create an STRUCTURE ARRAY.  This would occur when the FORM IS LOADED.


Public Structure DONOR
    Public strDSTATUS As String
    Public lngDNISADDRBKnum As Long
    Public strDENAME As String
    Public sngDFTE As Single
    Public sngDVBAL As Single
    Public sngDSBAL As Single
    Public lngDECLASS
    Public datDDate As Date
End Structure

This is the current FORM LOAD EVENT CDX:

Private Sub frmDONORS_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        'TODO: This line of code loads data into the 'PSCLVACCTm0DataSet.STAFF' table. You can move, or remove it, as needed.

    End Sub

Specifically, my primary question is how the following line of VB2005.NET Code


can be modified to read each ROW/ELEMENT(FIELD/COLUMN) sequentially in the TABLE and ASSIGN IT to the corresponding ROW STRUCTURE ELEMENT.

Basically, A FOR EACH STATEMENT to READ the MS_ACCESS TABLE would be the easiest way to loop thru the TABLE, but I'm not sure that'll work, being a VB2005.NET Newbie.  My experience tells me, I may have to write code(DO UNTIL) to check for a EOF Condition.

My secondary question then and I'm only looking for general direction and concept development here, is I then want to selectively use STRUCTURE ARRAY ELEMENTS to load /populate a GRID CONTROL and DISLAY the DATA on the FORM when it is LOADED? So, can I create/populate the DATAGRID CONTROL with the STRUCTURE ARRAY DATA on the FORM, when it is LOADED  and after I have created the STRUCTURE ARRAY?

Any guidance and assistance would be greatly appreciated.


Mike O
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Specifically, my primary question is how the following line of VB2005.NET Code


can be modified to read each ROW/ELEMENT(FIELD/COLUMN) sequentially in the TABLE and ASSIGN IT to the corresponding ROW STRUCTURE ELEMENT.

My primary answer is "it can't".  A TableAdapter fills a table in (so far as the user/application sees) one uninterrupted process.  You have two choices.  One is to use a DataReader rather than a TableAdapter.  That reads single record by single record and allows you to do things with that single record before the next one is brought.  The other is to continue to use the TableAdapter and then read through the filled Table row by row to create your Structure and add it to your array.  That is, you would in fact be "read[ing] each ROW/ELEMENT(FIELD/COLUMN) sequentially in the TABLE and ASSIGN IT to the corresponding ROW STRUCTURE ELEMENT" but you would be doing it by adding to, rather than modifying, the line of code that you quote.

On your secondary question, and remembering that you are looking for general guidance, my comment would be that you would have, in the DataTable that the TableAdapter above fills, a tool specifically built to display data (selected or otherwise) in a datagrid on a form.  There may be other reasons why you want to move values from cells in a row in a datatable into elements in a structure and then put the structure that corresponds to each row in an array.  But, it seems to me, you are essentially just replicating what a datatable already is.  A datarow is, in effect, a "structure": a collection of name/value "elements".  And a datatable is, in effect, an array of those structures.

Given that a datatable can be bound to a datagrid very simply, whereas binding an array of structures to a datagrid would be much more complicated, I wonder why?

mhottoAuthor Commented:

Thanks for taking the time, to read my question and formulate an answer.  Especially, helpful, since I'm a Newbie @ VB_05. And sorry, for the slow response.  Been handling other BOSS FIRE MISSIONS.

The reference to the "DATA READER" Object wasn't something that occurred to me, even though, I had come across it during tutorials, along the idea of datastreams.

To answer your question, as pertains why go to what seems like a complicated data structure coding problem, when the datagrid is analogous to a programmer defined structure.  I think a problem documentation LINK


 of what my application is doing and what I'm trying to accomplish is alot easier, than a lot of verbose text in this form.

Any additional guidance/comments/questions/suggestions would be appreciated, particulalry since I'm new to VB_05.  But, the points are yours.



when the datagrid is analogous to a programmer defined structure

That's not quite what I meant.  The datagrid is no more than a display and user-entry mechanism.  The point that I was trying to make was that a "dataTABLE is analogous to a programmer defined structure".  And my view then was - and it remains now, having looked at the link you provided - that there is unlikely to be anything that you can do with a programmer defined structure that is filled from a DataTable that you cannot do (much more easily) with the DataTable itself.  

As I said last time, binding a DataTable to a DataGrid or DataGridView is a doddle.  You can do it in the IDE GUI or with one line of code

   MyDataGrid.DataSource = MyDataTable

But binding a Structure to a DataGrid or DataGridView has, effectively, to be self-programmed.

If you want the DataTable to be available to other forms you can either declare it in a Module which has scope for those other forms or pass a reference to it to those other forms: which is just what you would have to do with a Structure.  If there is a relationship (or relationships) between different DataTables - e.g. the many to one POOL to DONOR relationship mentioned on the link - you can declare that relationship on the DataTables themselves and use it - perhaps with DataViews - to fill DataGrids or DataGridViews with whatever data, filtered and sorted in whatever orders you want, directly from those DataTables without having to put it into a Structure first.

I realise that a lot of what I am saying comes from having worked with data in VB.NET for a long time.  I'm familiar with what it can do and how to make use of it.  If you are happy working with Structures then it may be more efficient to continue to do so rather than having to grapple with unfamiliar objects and syntax.  But I'd certainly recommend you to at least have a look in the help file at DataRelations and at DataViews as, I think, they might save you a lot of lines of code.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mhottoAuthor Commented:
Appreciate the guidance.  What I've accomplished so, far is with the MS provided tool-set. And based on your experience and in my case no experience with VB_05 .NET.  It's probably best I go with that, rather than roll my own.

Thanks again.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.