CRUD Using Three Tier Architecture in C#

 Introduction:

In this article, we will learn that how can we apply the crud operations on a database table using the three tier architecture in c#.

We will continue this article with the example from the previous article, where we fetched the data from the database using the three tier architecture.

This time around we will perform the other data operations including insert ,update and delete respectively.

So, we will continue our code further on from the last article, and we will be working in the same project we created in our last example, so you can first check out this example from our previous article if you are unfamiliar with the Three tier architecture.

https://dotnetcodeblogs.blogspot.com/2021/05/three-tier-architecture-in-c.html  

Step: 1:

So, first up write the code to fetch the data from the database in DAL class which off course is present inside the data access layer.


Step 2:

We will insert the data into the Student table, so for that we will create a new method for writing the code for insertion.


Step 3:

Now we will write the code for the update operation in the our data access layer in DAL.cs


Step 4:

So, now lets write for the last CRUD operation, which is to Delete a record from the database.


Step 5:

So, at this point we are done with the data access layer, now we will write the methods inside the business access layer to implement all the crud operations.


Step 6:

So, now we write the code inside our presentation layer, which is off course our c# console application to implement all the methods which we have just defined inside the business access layer, so from our main method we will be calling each method to perform all the crud operations.


So here we are simple trying to call the required methods to implement the crud operations, we first populate top 3 records from the student table, then we inserted a new record, then we performed the update operation on a specific record, and at last we deleted a record from the database, after all the operations, we populated the students list again to see all the affects.

Press crtl+f5 to run the application and to see the output window.



 








 


Talha Mahmood

I have been developing Applications in Microsoft .NET technologies since 2015, and having more then 5 years of experience in .NET Technology and SQL database, also having hands in tools like C# Windows Forms, WPF, WCF, Asp.Net Web forms, Asp.Net Core, SSRS, LINQ, Entity Framework, Crystal Reports, SQL server, MySQL, MongoDB, Document DB, JQuery, JavaScript, Oracle, Web API.

Post a Comment

Previous Post Next Post