Passing data between tiers

  • Thread starter Thread starter ken hughes
  • Start date Start date
K

ken hughes

Hi,

I'm trying to pass data between the Data Access Layer and
the Business Process Layer of my app....

Is the best way to do this...

DAL
public function SavePerson(byval ds as dataSet) as boolean
.... code in here
end function

public function LoadPerson(byval ID as integer) as Dataset
.... code in here
end function

BPL (CPerson class)
public sub Save()
.... create the dataset (objDS)
.... create ref to DAL (objDAL)
.... objDAL.SavePerson(objDS)
end sub

public sub Load()
.... create ref to DAL (objDAL)
.... objDS = objDAL.LoadPerson(ID)
.... populate properties from dataset
end sub

Should I be passing byval or byref ??

Thanks .. Ken
 
I'm trying to pass data between the Data Access Layer and
the Business Process Layer of my app....

Is the best way to do this...

DAL
public function SavePerson(byval ds as dataSet) as boolean
... code in here
end function

public function LoadPerson(byval ID as integer) as Dataset
... code in here
end function

BPL (CPerson class)
public sub Save()
... create the dataset (objDS)
... create ref to DAL (objDAL)
... objDAL.SavePerson(objDS)
end sub

public sub Load()
... create ref to DAL (objDAL)
... objDS = objDAL.LoadPerson(ID)
... populate properties from dataset
end sub

Should I be passing byval or byref ??

Thanks .. Ken

Just use a DataRow instead of a DataSet if you are only saving or loading
one record at a time. Always use the smallest memory footprint type to
accomplish your purpose. This not only saves system memory, but means
there is less that needs to be transmitted over a network/internet.

It sounds like what you really want answered is the difference between
byval and byref? I would use the default byref for passing objects
around.

This topic covers the differences really well:
http://msdn.microsoft.com/library/default.asp?url=/library/en-
us/vbcn7/html/vaconArgPassMechanism.asp

Passing byVal does not make a copy with object types as it does with
value types. Any class including a DataSet/DataRow are reference/object
types. reference types are declared with the class keyword. base types
like integer, bool, or anything defined with the struct keyword are value
types.

Basically what you need to know with object types is that if it is passed
byref the called fuction can set the variable reference in the calling
code to a new/different instance of that type. If it is passed byval
then the calling code cannot set the variable to a different instance.
In either case (byval/byref) the calling code can make any changes it
wants to the properties of the passed in object, and those changes affect
the variable reference in the calling code. If you don't want the called
code to be able to modify the method arguement, then pass in a "Clone" of
the object instead of the original. See the ICloneable interface for
more details on that.

I hope this helps.

Michael Lang, MCSD
 
Back
Top