Solved

ASP.NET C# - Passing data between layers

Posted on 2004-04-20
6
2,966 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Highfive Gives IT Their Time Back

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!

 
LVL 2

Author Comment

by:Crazee
Comment Utility
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
Comment Utility
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
Comment Utility
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

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

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
This video discusses moving either the default database or any database to a new volume.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 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

16 Experts available now in Live!

Get 1:1 Help Now