Skip to main content

SQL Lite CRUD operation using Visual Studio Web Application

Problem: How do I perform CRUD operation in web?
Solution: I will explain in detail steps how to write a simple web application that is capable of crud operation in SQL server. 
  • From Visual Studio create a MVC web application. I used Visual Studio 2017.
  • Add entity framework core, sql server compact packages from NuGet browser if you want
  • Get a SQL lite database (mdf file) and add an employee table with columns, Id (int), name, address and phone number as varchar.
  • Copy it to the data folder in the application folder
  • Add a class named employee to the modal class with properties same as the column names in the employee table
  • Add a controller class named employees
  • Go to the appsettings.json file,  rename your copied database file to the same name as the database name in the connection string
  • Go to the layout page and add the newly created employees CRUD operation index page to the web layout
  • Build the project 
  • Launch the website by pressing F5
  • Check if you are able to go the employees index page from the website
  • If you get SQL connection string error, then double click on the mdf file in the data folder of the solution browser. This will open the database in the SQL explorer of visual studio. Right click and open the properties of the database, copy the connection string and replace the connection string of the appsettings.json file.
  • Check that the employees index page is opened from the website.
  • Click on the create link in the index page. And enter the details and try to save it. In case insertion of employee to the employee table fails due to primary key missing error, add the field to get the primary key from the create page of the employee.
  • Now everything should work ...... 
For step by step demo in Visual Studio 2017 visit
https://youtu.be/PWQL15kWPWE

Comments

Popular posts from this blog

Real time data to web application using Microsoft Signal R and Razor Pages

Today we are going to learn how to create razor pages and how to send run time value to the razor page using Signal R Create a new .NET core web application Add Signal R library by,  Add Client-Side Library dialog in the project, for Provider select "unpkg" and select the latest version from the drop down For Library, enter @aspnet/signalr@1, Add a new folder to the project named as Hubs The chat hub class inherits from HUb class that manages connections and messaging The send message is called to send the message to all the clients. MyHub.cs file contains the following code using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.SignalR; //using System.Threading.Tasks; namespace SignalRSample.Hubs {     public class MyHub : Hub     {         public async Task SendMessage(string user, string message)         {       ...

CRUD operation with WCF service and WPF client

 The database restored on local server WCF Service is talking to the database. Used Visual Studio 2019, entity framework 6 for data base operations from the service. The service exposes the following API’s.  The WCF contracts has both synchronous and asynchronous API's The client is in WPF. It has three windows, main window, customer window and order window as follows. The client uses the WCF service for database operations. When customer button is clicked, the customer window is displayed as below. We can perform CRUD operation from it. The customer can be searched based on ID. New customer window The order button launched order window. It has combo box to choose the customer ID. On selecting the ID, the order details are displayed in the data grid as follows. The source code is available in the GIT hub, URL below: https://github.com/SwagatikaGoswami/WPF_WCF_CRUD.git

Online Exam App with .NET Core Web API and Blazor Client

 We will develop an app that can host online exam. It will have the feature to register user, allow the user to log in. Dashboard for creating sample tests.  The code is shared in GIT hub repository https://github.com/ SwagatikaGoswami/ OnlineExamApp.git The database is MySQL database. The server is a WEB API .NET Core service that uses entity framework for DB operations. The client is a web assembly blazor application. The password stored in the database is encrypted. Register window is as follows. It checks for the mandatory fields. The log in page is as follows: The admin dashboard after logging in  The admin dashboard when new test button is clicked. It uses a Blazor component for adding new test samples.