Re: Object scope issue...

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hi there...

When the user clicks to save, I am actually running a stored procedure that
inserts a row in our SQL Server db. I am not using a datagridview. In fact I
have never used one yet. Do they actually work well becasue I may have a
need for that in the application I am currently developing.

When the user clicks the "Save" button on the form, I then first check to
see if a parent class has already been instantiated. If it has not, I
instantiate the "parent" class. If it has already been instantiated (and
this is where I was having the problem) then I do not need to create a new
instance. Then, I call the parent objects "update" method. This update
method - does the insert (or update) into the database for the parent table
and then also instantiates a related "child" class and calls it's update
method as well to store some child data.

I think I may have it figured out now... I have created a public variable
at the form level because it is here that I will need to instantiate the
object and possibly persist it for a while. I realized that I was actually
"destroying" the parent object in the code at the end of the Save buttons
"click: event (as part of the clean up) - so I wasn't getting desireable
results.

I will have to check that book out...

Thanks, Brad

"RobinS" <robins@xxxxxxxxxxxxxxxx> wrote in message
news:s9WdnTlme9n7-TTanZ2dnUVZ_hqdnZ2d@xxxxxxxxxxxxxx
How is your business object set up? When you say the user clicks to save a
row, are you using a datagridview, or do you mean just to add a new
object?

Have you checked out Deborah Kurata's book "Doing Objects in VB2005" ? It
talks about how to handle the state of an object, and how to handle
updates. Great book.

RobinS.
GoldMail, Inc.
-------------------------------------
"Brad Pears" <bradp@xxxxxxxxxxxxxxxxxxxxx> wrote in message
news:OMG8tNEaIHA.3940@xxxxxxxxxxxxxxxxxxxxxxx
I just have a question about how objects should be used in situations
where you want to preserve an object's state while performing some
particular function.

In my vb.net 2005 app, a user enters data and then clicks a "Save"
command
button to save the row. If the user simply changes existing data on the
form, (meaning a row already exists) I only do a database update.
However,
if the user was adding a new row I would have first created a new
instance
of the object and subsequently added the row data to the database.

I set up the object as a "public" variable in my main vb module like
this...

"public MyObj as clsMyObj"

Then in the "Save" command button code, I first check to see if MyObj =
nothing. If so, I then create a new instance of the object (MyObj=new
clsMyObj) and run code that inserts the new row.

If the user were to go back and modify some data and clicks the "Save"
command button again, I
would expect my code above (if MyObj = nothing ) to be false and I would
then just update the data as opposed to updating it.

Is this typically how one would control an objects scope - by setting as
a public variable and checking to see if
the object = nothing or object = something? If so than does this mean
that for any object that I need to preserve scope, I need to setup as a
public variable?

I am new to OO design etc... and I want to make sure that I don't have
copies of objects all over the place etc... It seems that there must be a
better way to do this?

Help!

Thanks, Brad





.



Relevant Pages

  • Re: Object scope issue...
    ... So, the "update" method on the Parent class, inserts or updates parent ... What I was doing in my "Save" command button code was setting the parent ... I only do a database update. ... Is this typically how one would control an objects scope - by setting as ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Object scope issue...
    ... scope is set up. ... a user enters data and then clicks a "Save" command ... I only do a database update. ... Then in the "Save" command button code, I first check to see if MyObj = ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Object scope issue...
    ... So, the "update" method on the Parent class, inserts or updates parent data ... child class and calls it's "update" method which then either ... What I was doing in my "Save" command button code was setting the parent ... I only do a database update. ...
    (microsoft.public.dotnet.languages.vb)
  • Typed datasets using oleDB
    ... database in VB.Net. ... If I add a parent record to the dataset and then a child ... updated using the dataAdapter.Updatecommand. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Altering Table - Adding Primary Key With References
    ... In identity relashionship primary key from parent table migrate in child ... In ALTER TABLE command works similarly. ... > Relations between tables can be defined in the database but they are not ...
    (microsoft.public.fox.vfp.dbc)