Objects/Datasets - just a newbie bit of logic assistance required please!

cadwalli

Active member
Joined
May 27, 2010
Messages
41
Location
United Kingdom
Programming Experience
10+
Hi

Im trying to understand whether i have my "concept" of what im doing right here.

Basically, ive got some data in a DB tables called "Categories". This is just like a table of codes and descriptions etc.

Now in my code I have an Object/Class also called category which has the proerties matching the table plus some manipulation events to allow me to use the properties.

What im wondering is - whats the best method to load data into that object.

Do I use a dataset to load the data, then all those records retrieve load into obejcts so i basically have "x" number of objects in a collection.

i.e.

collectionObj1 - category1, collectionobj2 - category2

then manipulate each object as required and write it back to the dataset then to the db

OR

or is it best just to load into the dataset, then a selected record (i.e. pressing Edit button) in that dataset load into a single object of type category and manipulate, write back to the set and then back to the database - then if the user wants to change another record load that into the obejct and do the same.

Hope this makes sense.

Thanks in advance.
 
Of course if my logic is completely wrong and im going about this the whole wrong way then please tell me haha.

I know i can maniuplate and bind data directly from the dataset/adapters/views etc, but i was ssuming i should have classes/objects for my data to manipulate it in true OO fashion.

I have been known to be wrong (according to the other half!)
 
If you create a dataset, datatable, and/or datarow there is no need to create a class like this. The datarow objects already have this exact ability. You should be able to create a datarow object that holds all these fields and then you can just use a DataAdapter and fill your dataset.
 
THanks ss7Thirty

That is what i was kind of thinking, but people keep telling me i should created "objects" to manipulate the data and write it back.

I guess a class/structure therefore is only really useful if i wanted to say create a "temporary" table in memory and then write it back to a db for hte first time?
 
There are various advantages to defining your own classes, or having them defined for you by a tool. Working just with DataTables is fine and will get the job done but very few professional applications would be built that way.
 
It has its advantages, which may depend on the circumstances. You might also opt not to use DataTables at all, but rather use LINQ to SQL, the Entity Framework or some other ORM tool. That will handle the data access and the entity classes, plus also probably provide a LINQ interface, making the data easier to work with. It's really up to you whether you start out old school or jump straight into something like that. There's something to be said for both approaches.
 
So is it my "understanding" of what im trying to achieve whats wrong? Youll have to forgive me, we're moving from a Progress DB system (basic objects) to VB and SQL Server.

Ive been told we should use objects and whilst i understand why i should use and how they work (although its been a while since I was at Uni!) im failing to see the logic of how ill use them in my programming.

Am i right in thinking that id have my underlying DB with tables such as :

ItemTable: [fields] ItemNo, Description, Lead Time etc...
PurchaseOrderTable: [fields] PO No, PO Line, Item, Qty, Supplier etc...

But in my code I should create the object which can control reading the data from teh DB into the objects datasets for manipulation but only with the properties that the object would need.

For example, if I need a class that would control the Purchase ORder details, I could create a class called "POItemClass". In that class all id want to ever use is PO NUmber, Line, Item, Item Description and i want my class to do all the work so people dont have to know how to get to that data, so I could create a class such as:

POItemClass

Property PoNo
Property PoLine
Property Item
Property ItemDescription

Method LoadPOs
Method ShowPONo
Method UpdatePODescriptuon

Thereby the class only needs to process the information required and not load in all the data from teh DB for each field etc.

Hope this makes sense.

Ian
 
I think you are over-thinking it a bit. .NET has built in objects to handle all this stuff already you can create a dataset which uses their object to inherit all the basic stuff you need and you just need to specify your schema. It works a little like progress in that you can just use For Each to loop through the data which was one of the cool aspects of Progress IMO.
 
I probably am overthinking it all a little bit, i loved working with Progress so its a big change for me. Especailly as with no budget im having to learn this all self taught as we are moving to Syteline 8 and that uses "generic" types of Objects, so one object can be used to control data retrieval/write todifferent tables. i.e. a "generic" object can use Purchase orders or customer orders - which is where the company envisages us doing the same thing for our own bespoke requirements.
 

Latest posts

Back
Top