[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Convert project to two-tier

Posted on 2006-05-23
10
Medium Priority
?
239 Views
Last Modified: 2016-08-29
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
0
Comment
Question by:sirbounty
  • 7
  • 3
10 Comments
 
LVL 67

Author Comment

by:sirbounty
ID: 16745912
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
0
 
LVL 34

Accepted Solution

by:
Sancler earned 2000 total points
ID: 16752422
I don't think you've done anything wrong so far - but what turns out to be right or wrong will depend on what else you do.  Perhaps, I don't know, these two steps are not quite what you want.

  Dim mobjSales As SalesData  'instance of SalesData

That, although it declares mobjSales as being of the CLASS type SalesData does not actually create an INSTANCE of that class.  To do that, you will need New somewhere.

and

  Dim mblnInitialized As Boolean = False  'Boolean to prevent combo code from running

This may be superfluous, as frmStoreSales already has a variable - mblnListLoaded - declared for a similar purpose and it is that one - mblnListLoaded - to which the cboStoreNames_SelectedIndexChanged sub actually refers.

What are you intending to do next?  (Some of) what needs to be done can be seen from the TaskList.  If that is not already showing you can call it up from the View Menu with OtherWindows > TaskList.  That shows that frmStoreSales is now referring to dataadapters and datasets which are not declared within it (or in any scope which it can see).  So you're going to have to re-code to get the data that frmStoreSales needs from your data layer rather than direct from those dataadapters/datasets.  That, in turn, means that you are going to have to get that data from the database into your data layer and then expose some methods or properties in the data layer from which your form can get it.  You had, in one of your previous exercises, just such a set-up.  So your best bet is probably to use that as your model.

Roger
0
 
LVL 67

Author Comment

by:sirbounty
ID: 16752585
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.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 34

Expert Comment

by:Sancler
ID: 16753775
>>
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
0
 
LVL 67

Author Comment

by:sirbounty
ID: 16753948
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
0
 
LVL 67

Author Comment

by:sirbounty
ID: 16753968
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. ;^)
0
 
LVL 34

Expert Comment

by:Sancler
ID: 16754607
I'm utterly confused.  I thought you were now working on stores and sales, not books and authors.

Roger
0
 
LVL 67

Author Comment

by:sirbounty
ID: 16754641
Doh!
My mistake..
0
 
LVL 67

Author Comment

by:sirbounty
ID: 16754937
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.
0
 
LVL 67

Author Comment

by:sirbounty
ID: 16755515
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...

http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21862762.html
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Integration Management Part 2
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question