Solved

ASP.NET C# - Passing data between layers

Posted on 2004-04-20
6
2,977 Views
Last Modified: 2011-02-24
Hi,

I'm building a system where
aspx and code behind are my presentation layer ( validation happens in code behind ),
the application logic is in separate classes,
the data access logic is in separate classes.

Most of the time I will need to access one row ( usually joined tables ) at a time - except for read-only reports.

Is it possible to create empty DataSet in the application layer and populate it with data ( one row ), then pass it to data layer which uses this DataSet to update the DB?

Overall I'm looking for a more elegant sollution than passing SQL statments...


I'm willing to incrase points if I am able to use the sollution...also If you could provide me with a better architecture ( with examples ) I could use I'm willing to give extra points.

please ask if the question is not clear

thanks
0
Comment
Question by:Crazee
  • 3
  • 3
6 Comments
 
LVL 29

Expert Comment

by:David H.H.Lee
ID: 10875552
Crazee,
>>Most of the time I will need to access one row ( usually joined tables ) at a time - except for read-only reports.
-If the server allow, you can store all the data into dataview first. After that, you can use RowFilter(built in function inside dataview itself) to filter the desired output based on the previous retrieved data. Now, you can access one row or every row(eg:except for read-only reports) at the same time without retrieve data from server everytime.

>>Is it possible to create empty DataSet in the application layer and populate it with data ( one row ), then pass it to data layer which uses this DataSet to update the DB?
-Are you looking for some action like you want to get the data from dataset and update the dataset in the same time? Corret me if i misunderstand your question. If this is your problems, why don't you just use SqlCommandBuilder to overcome this problem instead of create an additional dataset and passing to data layer and update the dataset? I only think this method can retrieve data and update the dataset at the same time.

Hope this help. If this not clear, please give more explanations about what you want to accomplish.



0
 
LVL 2

Author Comment

by:Crazee
ID: 10885542
I'm looking for a good way of passing data between the classes. Most of the time I will need data to populate one instance of an object.
I know that if you retrieve data from db you can pass it in a form of DataSet or DataReader. In that case if you get input from the user, can you create an empty DataSet and populate it with data received from the user? I'm fairly new to .NET so the whole concept may be wrong.
0
 
LVL 29

Expert Comment

by:David H.H.Lee
ID: 10885684
Crazee.
Since you're using 3-tier development, you should be able solve this kind of problem easily. Ok, now i want to ask one more question before give you the whole idea of the solutions.

>>can you create an empty DataSet and populate it with data received from the user
-Why you so interest create an empty Dataset and populate with data received from user? Can i know the purpose? Possible for you give me the exact senario. More details about this. Normally, i like to use DataView to filter(use RowFilter) what i'm need.
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 2

Author Comment

by:Crazee
ID: 10894947
I don't have to use DataSets this way. I just thought that if it can be used to pass data from DB, maybe I could use it to pass data to DB as well - I know that it's possible to update existing DataSet, but I was thinking of creating an empty one.

The point of my question was weather my logic was right, and if not - I would like to find another solution.

Let's have a sample scenario.

Add Project:

User chooses to add new project
Fills the form
Submited data is validated in code behind and if is ok - new class Project is created and populated with this data
Class Project calls save() method of another class that can access DB

here's the question: what should I pass in the save() method?

What would be the case with Edit Project if I have to grab the data from the DB first?

if it's not clear please ask

0
 
LVL 29

Accepted Solution

by:
David H.H.Lee earned 250 total points
ID: 10929489
Sorry for my delay, Crazee.

-Crazee, i tell you what i done in 3-tier development. I will create 3 layer
Presentation Layer, Business Layer and Data Layer like what you had done.
Presentation Layer - contains all web/html code
Business Layer - contains all business component(include classes, all the operations will be return here)
Data Layer - only use to access your db(insert, update,delete,..etc)

>>what should I pass in the save() method?
-I will put it in Data Layer. You can call this function from your predefined classes. If you need to pass somethings to the business layer, you'll need to assign it into your object variable.
eg:
Car sportCar;
sportCar=new Car();
sportCar.Number="ASC 8888";
sportCar.Save();
However, if you like to pass variables that you think not include inside business layer, you can pass it as local parameter inside save() method.
eg:
sportCar.Save(yourVariableName);

>>What would be the case with Edit Project if I have to grab the data from the DB first?
-You always can grab the db first no matter it edit mode or read-only mode. Please give more details about what you trying to do with this problem.

Crazee, if you want exact solutions, it's better you give the exact senario instead of this example.

If you already get what the solutions before my comments, you can request to close it at Community Support. Admin will handle it else i'll glad to continue this thread as well.

Regards
x_com

0
 
LVL 2

Author Comment

by:Crazee
ID: 10956498
I got it working.

I'm passing data between classes using data sets instead of assigning data to properties.
( if you're interested I can post more details )

Basically what I was looking for was a theoretical discussion on possible architecture and the way of passing data.
You provided me with your sollution and although I'm not going to use it, I appreciate your time.

cheers
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

856 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