Link to home
Start Free TrialLog in
Avatar of sirbounty
sirbountyFlag for United States of America

asked on

Convert project to two-tier

I have the following project that allows the user to select a store name from a combo box, and populate two data grids with the results.

It works in its current form.  I'm looking for help/guidance in converting it to a two-tiered project (moving the data access to a SalesData class).

Though not homework, I'd like to treat it as such, so that I can "hopefully" get a better grasp of what I'm actually doing here.

So, if you have the patience to help tutor me here, I'd be very grateful...

Thanx

https://filedb.experts-exchange.com/incoming/ee-stuff/114-ch4.zip
Avatar of sirbounty
sirbounty
Flag of United States of America image

ASKER

Here's what I've done (hopefully moving me in the right direction):

1) Create the data tier (Right-click the project, add Component, naming it SalesData)

2) Cut/Paste the data adapters, connection and datasets from the form to the data module

3) Removed data associations from the controls:
   a) Deleted ValueMember property from the combobox
   b) I don't currently see how to remove the definitions for the two grids - DataBindings is empty?

4) Added these two module-level declarations to the form:
  Dim mobjSales As SalesData  'instance of SalesData
  Dim mblnInitialized As Boolean = False  'Boolean to prevent combo code from running
ASKER CERTIFIED SOLUTION
Avatar of Sancler
Sancler

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The boolean was just case I prefer that variable than the ListLoaded - I have that changed in my code at this point.
As for the dataadapters, datasets, etc - I 'thought' I could cut/paste them onto the SalesData class?

My main objective is to simply (and correctly) walk through the process of taking a 1-tier and converting it to a 2-tier.
If that goes in a different direction than what I've learned so far, I'm okay with that...

I'll make a few more modifications and then post the new version.
Avatar of Sancler
Sancler

>>
As for the dataadapters, datasets, etc - I 'thought' I could cut/paste them onto the SalesData class?
<<

Yes, you can.  But that is just the objects themselves.  The code that uses those objects is still - on "the story so far ..." - in the Form's code.  So, for instance, if you want to call

        daStoreNames.Fill(DsStoreNames1)

you will need to do so in an instance of the SalesData class, not in the Form.  So you would (a) also need to cut and paste that code over - having decided where in your class to put it - and (b) then find a way of getting the information about store names from your instance of that class, once it had called that code, into the combobox.  

I'm deliberately being a bit obtuse as, I think, the idea of the exercise is for YOU to work out what needs to be done (and why) and how to do it ;-)

Roger
Okay, if my form_load now has this: (comments here are my 'thinking out loud' about what's going on)

 Private Sub frmTitles_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim dvLastName As New DataView  'This is a dataview to hold an sorted list of the author's names (retrieved from the data tier)

        Try
            'Get the data from the data tier
            mobjAuthors = New PubsDatabase  'Instatiates the class
            dvLastName = mobjAuthors.getNames  'populates the dataview with the 'sorted' datasets?

            With cboNames
                .DataSource = dvLastName  'sets the cbo's datasource property to be the dataview object acquired from the data tier
                .DisplayMember = "lname"  'This 'was' name, but I know name was a concat'd field, I switched it to lname to keep it simple
                .ValueMember = "au_id"  ' Here I'm getting a 'could not bind to display member'

So, by 'display' member, is it referring to the prior property setting?  Cause stepping through it, that seemd to go through fine.  If the problem is with the value, then something's wrong with my function... (?)

    Public Function getNames() As DataView
        daAuthors.Fill(DsTitlesAuthors1)
        daTitles.Fill(DsTitlesAuthors1)
        daTitleAuthor.Fill(DsTitlesAuthors1)
        Return dvNames
    End Function
I think this would have been easier starting from scratch though.
Manipulating an already existing project has proved to be a bit of a challenge...
I appreciate your obtuseness. ;^)
I'm utterly confused.  I thought you were now working on stores and sales, not books and authors.

Roger
Doh!
My mistake..
Now I'm confused - the zip attachment appears to be books/authors instead of stores/sales... :(

Perhaps I should just cut my losses here and start from scratch.
Okay, I started it over - just the form class.
I'll open another question to convert it to two, but I've got a small problem in this form...

https://www.experts-exchange.com/questions/21862762/My-favorite-error-reappears.html