Solved

Data Manipulation - Best way to process

Posted on 2009-04-10
5
194 Views
Last Modified: 2013-12-17
Greetings all

I am relooking at the way I handle data - a recent discussion with a colleague left me wondering if my way was appropriate and what other, posisbly better ways were out there.

Currently I use  a Datalayer that extracts the data and then passes back a list of objects.

The List is then linked to the appropriate controls, where no updating is required. Where the data will be changed, I convert the List into a DataTable or DataSet and link to the Control. For updating I can use either a SQL Command object or pass back inidividual records to a stored procedure.

The plus, to me, of passing Lists is taht it allows complete separation of my DataLayer and presentation layer. As to converting to DataTable/DataSet - I've always done it liek that, but if there are better ways, I'm up for it.

Any thoughtd?


In advance, thanks!!

    allanmark
0
Comment
Question by:allanmark
  • 2
  • 2
5 Comments
 
LVL 26

Accepted Solution

by:
Anurag Thakur earned 300 total points
Comment Utility
the design looks good till the time you start converting it to a datatable or a data set
what is the requirement you are trying to do that
a generic list List<T> provides you with everything you need to perform as with the dataset or a datatable
0
 

Author Comment

by:allanmark
Comment Utility
Thanks!

One common requirement is working with grdiView - insert, edit, etc.

If I understand what you are saying then whatever I do with a DataSet/Table (see  snippet example 1 and example 2 and example 3) I can do with a List, in addition to all else that the List offers me.

I've linked a list to the gridview and can browse through the data, etc. But if I delete the record via the gridview then I don't have a way to access the deleted record (see EG 2) or if  I want to check
record status (EG 3) and update if necessary,

EG 1:
 

DataRow newRow = dsBranches.Tables["Branches"].NewRow();

newRow["id"] = 0;

......

.....

dsBranches.Tables["Branches"].Rows.Add(newRow);
 
 

EG 2:
 

if (dsBranches.Tables["Branches"].Rows[rowIndex].RowState == 

    DataRowState.Deleted)

   .....

   ............
 
 

EG 3:
 

if (dsBranches.Tables["Branches"].Rows[rowIndex].RowState == 

    DataRowState.Modified)

   ProcessUpdate (..., ..., ...)

   ............

Open in new window

0
 
LVL 6

Expert Comment

by:hehdaddy
Comment Utility
I would suggest dropping your object layer and return the data from the database as a DataSet, then bind to your controls. The changes are made to your DataSet, which are sent to the database.

The key is to remove the number of moving parts and take advantage of .NET's data handling.
0
 
LVL 26

Assisted Solution

by:Anurag Thakur
Anurag Thakur earned 300 total points
Comment Utility
eg 1 can be achieved by creating a new <T> object and then adding it to the list
List.Add(<T>)
create a unique id so that you can differentiate between newely added objects

eg 2: create a property for deleted (boolean) and just update it and while doing databind you can select non deleted objects only

eg 3: again add a property where you change a timestamp to find if something has been modified or not
0
 

Author Closing Comment

by:allanmark
Comment Utility
Many thanks!!!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now