F
Frank Romano
Hey, everyone. I have an application that was written in VB6 that I have to
rewrite in VB.NET 2003 and I am completely lost. I have tried finding
answers to my questions in MSDN and the newsgroups, but I'm only finding
bits and pieces that just don't add up for me because I must not be using
the right search words. Anyway here is what I need help with.
The existing app would best be described as being a "customer-orders" type.
It uses classes to represent the various business objects. The main ones
are compound objects, the containing object having details specific to a
single instance (such as a "customer" or an "order"), with embedded "typed
collection" classes that would be like "orders for this customer" or "items
for this order". The UI lets the user specify a particular "Parent ID"
which is passed to the respective collection's "Item" method and gets back
the desired instance of that type. The collection class reads the necessary
details from the database and assigns the values to the instance properties.
Once populated, the UI interacts with the object and the contained objects,
not the database. Conversely, when told to save the changes, the class
reads the values out of the instance and writes them back to the database.
The embedded classes and their data are implemented as typed collections,
there is no data binding being used. The UI isn't binding either. Forms
have methods that assign the values from the instance to the various
controls (text boxes, listviews, etc.) or scrapes changes from the UI back
into a particular object. It works, but it is really cumbersome and
inefficient, particularly since we want to be able to use these business and
data layer objects for both Windows clients and eventually web browser
clients.
What I have to do is rewrite the app so that the UI can bind to the business
objects and the business objects in turn bind to the data layer. I
understand the basics of the vbobjectbinding example, but I am completely
confused about how I can in turn bind the class to its data source without
having to resort to the existing app's approach of manually assigning the
property values to the datarows or query parameters. I guess what I want to
do is something like this:
UI passes a specific ID (i.e., "Customer Number") to the Item property of a
business layer object. That in turn executes a method like
"GetCustomerAndOrders(ByVal CustomerID As Integer)" which runs a parameter
query that populates a typed dataset with the details related to that ID (a
datatable containing just the single Customer record, and another datatable
containing the Orders for that Customer ID. Once the dataset is ready,
instead of doing assignments to properties (ThisCustomer.CoName =
ds.customer.cust_co_name) or walking the Orders table and manually
constructing the collection of order headers (For Each dr in ds.orders.rows
.... ThisCustomer.Orders.Add(New OrderInfo(...)), I want to be able to bind
the properties directly to the underlying datarow. In the case of the
"orders" collection, I want the collection to be complex-bound and serve-up
instances of "OrderInfo". When the user sends changes back, I want to be
able to just execute the Update methods without having to scrape the values
from the instance objects. I imagine this would require storing the dataset
with the parent object, and using references to the corresponding
datatables.
What totally confuses me is what I should be specifying for the Inherits
and/or Implements directives to make this work, and then how to write the
binding routines that will pull this off. I have come across partial
examples that say use IBindingList or ArrayList or a specialized collection,
but these are all focused on the UI binding and don't show anything about
how to propagate binding to a dataset. There are also a number of examples
that touch on this using built-in capabilities of VS2005/ADO.NET 2.0, but
that's of no help to me in the present.
Can someone please point me to a comprehensive example of how create a
Windows Forms application to do this using VB 2003 and ADO.NET 1.1? Thanks.
rewrite in VB.NET 2003 and I am completely lost. I have tried finding
answers to my questions in MSDN and the newsgroups, but I'm only finding
bits and pieces that just don't add up for me because I must not be using
the right search words. Anyway here is what I need help with.
The existing app would best be described as being a "customer-orders" type.
It uses classes to represent the various business objects. The main ones
are compound objects, the containing object having details specific to a
single instance (such as a "customer" or an "order"), with embedded "typed
collection" classes that would be like "orders for this customer" or "items
for this order". The UI lets the user specify a particular "Parent ID"
which is passed to the respective collection's "Item" method and gets back
the desired instance of that type. The collection class reads the necessary
details from the database and assigns the values to the instance properties.
Once populated, the UI interacts with the object and the contained objects,
not the database. Conversely, when told to save the changes, the class
reads the values out of the instance and writes them back to the database.
The embedded classes and their data are implemented as typed collections,
there is no data binding being used. The UI isn't binding either. Forms
have methods that assign the values from the instance to the various
controls (text boxes, listviews, etc.) or scrapes changes from the UI back
into a particular object. It works, but it is really cumbersome and
inefficient, particularly since we want to be able to use these business and
data layer objects for both Windows clients and eventually web browser
clients.
What I have to do is rewrite the app so that the UI can bind to the business
objects and the business objects in turn bind to the data layer. I
understand the basics of the vbobjectbinding example, but I am completely
confused about how I can in turn bind the class to its data source without
having to resort to the existing app's approach of manually assigning the
property values to the datarows or query parameters. I guess what I want to
do is something like this:
UI passes a specific ID (i.e., "Customer Number") to the Item property of a
business layer object. That in turn executes a method like
"GetCustomerAndOrders(ByVal CustomerID As Integer)" which runs a parameter
query that populates a typed dataset with the details related to that ID (a
datatable containing just the single Customer record, and another datatable
containing the Orders for that Customer ID. Once the dataset is ready,
instead of doing assignments to properties (ThisCustomer.CoName =
ds.customer.cust_co_name) or walking the Orders table and manually
constructing the collection of order headers (For Each dr in ds.orders.rows
.... ThisCustomer.Orders.Add(New OrderInfo(...)), I want to be able to bind
the properties directly to the underlying datarow. In the case of the
"orders" collection, I want the collection to be complex-bound and serve-up
instances of "OrderInfo". When the user sends changes back, I want to be
able to just execute the Update methods without having to scrape the values
from the instance objects. I imagine this would require storing the dataset
with the parent object, and using references to the corresponding
datatables.
What totally confuses me is what I should be specifying for the Inherits
and/or Implements directives to make this work, and then how to write the
binding routines that will pull this off. I have come across partial
examples that say use IBindingList or ArrayList or a specialized collection,
but these are all focused on the UI binding and don't show anything about
how to propagate binding to a dataset. There are also a number of examples
that touch on this using built-in capabilities of VS2005/ADO.NET 2.0, but
that's of no help to me in the present.
Can someone please point me to a comprehensive example of how create a
Windows Forms application to do this using VB 2003 and ADO.NET 1.1? Thanks.