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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Saber ShaikhPosted Jan 5, 2015, 4:12 AM
http://aspnettutorialscode.blogspot.in/2013/11/3-tier-architecture-example-in-aspnet.html
Thank You
Wim SturkenboomPosted Jan 4, 2015, 3:37 AM
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.
Anupam SinghPosted Jan 4, 2015, 3:06 AM
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.