3-tier architecture
how can I insert data in database using 3-tier architecture?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Anupam SinghRank #643 · 3.7K reputationPosted Jan 3, 2015, 10:06 PM EST
Now a days we dont prefer code ado.net library or other core database libraries instead we use ORM(Object Relational Mapping) frameworks like Entity Framework , nHibernate .. etc.
in 3 tier we separate layers in UI,Business Layer and Database.
Now your UI layer should not directly depend on Database instead you will have to use business layer to communicate database. so to insert data in table in responsibility of Business Layer, which will pass objects to ORM.
Wim SturkenboomRank #2,527 · 554 reputationPosted Jan 3, 2015, 10:37 PM EST
A class for your database work
class mydb
{
public static int updateUser(some parameters, out string errmsg)
{
// connect to database
...
// execute query
...
// return result of query; -1 on error (SQL exceptions), else number of affected rows
...
}
}
A class for your business logic
class mybll
{
public static int updateUser(some parameters, out string errmsg)
{
// validate parameters, return -1 on error
...
// update user information in database
return mydb.updateUser(some parameters, out errmsg)
}
}
And the last class will be your web page with a method to update the user information (on a button click)
protected void btnUpdUser_Click(object sender, EventArgs e)
{
string errmsg = "";
int affectedrows = mybll.updateUser(tbUsername.text, tbPassword.text, out errmsg);
if(affectedrows == -1)
{
// error
}
}
I don't do entity frameworks or whatever, just plain stuff.
Saber ShaikhRank #1,687 · 905 reputationPosted Jan 4, 2015, 11:12 PM EST
http://aspnettutorialscode.blogspot.in/2013/11/3-tier-architecture-example-in-aspnet.html
Thank You