filmov
tv
Create ASP NET Core Web Application With SQL Server Database and CRUD Operations | .Net Core 8.0
Показать описание
Create ASP NET Core Web Application With SQL Server Database and CRUD Operations | .Net Core 8.0
***************************
Create Your First ASP.NET Core Web Application with Database Integration. Connect an ASP.NET Core Web Application to a SQL Server Database.
Perform basic CRUD operations in ASP.NET Core. Add, View, Update, and Delete data in a SQL Server Database using an ASP.NET Core Web Application.
***************************
DBScript :
CREATE DATABASE [ProductManagementSystem_DB];
CREATE TABLE [dbo].[Products](
[Id] [int] IDENTITY(1,1) NOT NULL,
[ProductName] [nvarchar](255) NOT NULL,
[Address] [nvarchar](255) NULL,
[Country] [nvarchar](255) NOT NULL,
[State] [nvarchar](255) NOT NULL,
[City] [nvarchar](255) NOT NULL,
[ProductionDocument] [nvarchar](255) NULL,
[CraetedOn] [datetime] NULL);
CREATE PROCEDURE [dbo].[sp_DeleteProduct]
@Id INT
AS
BEGIN
DELETE FROM Products
WHERE Id = @Id;
END;
CREATE PROCEDURE [dbo].[sp_GetAllProducts]
AS
BEGIN
SELECT * FROM Products;
END;
CREATE PROCEDURE [dbo].[sp_GetProductById]
@Id INT
AS
BEGIN
SELECT * FROM Products
WHERE Id = @Id;
END;
CREATE PROCEDURE [dbo].[sp_InsertProduct]
@ProductName NVARCHAR(255),
@Address NVARCHAR(255) = NULL,
@Country NVARCHAR(255),
@State NVARCHAR(255),
@City NVARCHAR(255),
@ProductionDocument NVARCHAR(255) = NULL
AS
BEGIN
-- Check for duplicate ProductName
IF EXISTS (SELECT 1 FROM Products WHERE ProductName = @ProductName)
BEGIN
PRINT 'Duplicate ProductName exists';
RETURN;
END
INSERT INTO Products (ProductName, Address, Country, State, City, ProductionDocument)
SELECT SCOPE_IDENTITY() AS NewProductId;
END;
CREATE PROCEDURE [dbo].[sp_UpdateProduct]
@Id INT,
@ProductName NVARCHAR(255),
@Address NVARCHAR(255) = NULL,
@Country NVARCHAR(255),
@State NVARCHAR(255),
@City NVARCHAR(255),
@ProductionDocument NVARCHAR(255) = NULL
AS
BEGIN
-- Check for duplicate ProductName excluding the current record
IF EXISTS (SELECT 1 FROM Products WHERE ProductName = @ProductName AND Id != @Id)
BEGIN
PRINT 'Duplicate ProductName exists';
RETURN;
END
UPDATE Products
SET ProductName = @ProductName,
Address = @Address,
Country = @Country,
State = @State,
City = @City,
ProductionDocument = @ProductionDocument,
CraetedOn = GETDATE()
WHERE Id = @Id;
END;
Tools Used: Visual Studio 2022 and SQL SERVER Management Studio
☕ Buy me a Coffee (Channel Support through Donation)
📻 Recommended Courses
Subscribe to this channel
Must buy Programming Laptops :
Share, Support, Subscribe Now :
⭐️Tags : ⭐️
#dotnetcore
#netcorewebapi
#crudoperations
Thanks for watching. 😊😊 🙏🙏
***************************
Create Your First ASP.NET Core Web Application with Database Integration. Connect an ASP.NET Core Web Application to a SQL Server Database.
Perform basic CRUD operations in ASP.NET Core. Add, View, Update, and Delete data in a SQL Server Database using an ASP.NET Core Web Application.
***************************
DBScript :
CREATE DATABASE [ProductManagementSystem_DB];
CREATE TABLE [dbo].[Products](
[Id] [int] IDENTITY(1,1) NOT NULL,
[ProductName] [nvarchar](255) NOT NULL,
[Address] [nvarchar](255) NULL,
[Country] [nvarchar](255) NOT NULL,
[State] [nvarchar](255) NOT NULL,
[City] [nvarchar](255) NOT NULL,
[ProductionDocument] [nvarchar](255) NULL,
[CraetedOn] [datetime] NULL);
CREATE PROCEDURE [dbo].[sp_DeleteProduct]
@Id INT
AS
BEGIN
DELETE FROM Products
WHERE Id = @Id;
END;
CREATE PROCEDURE [dbo].[sp_GetAllProducts]
AS
BEGIN
SELECT * FROM Products;
END;
CREATE PROCEDURE [dbo].[sp_GetProductById]
@Id INT
AS
BEGIN
SELECT * FROM Products
WHERE Id = @Id;
END;
CREATE PROCEDURE [dbo].[sp_InsertProduct]
@ProductName NVARCHAR(255),
@Address NVARCHAR(255) = NULL,
@Country NVARCHAR(255),
@State NVARCHAR(255),
@City NVARCHAR(255),
@ProductionDocument NVARCHAR(255) = NULL
AS
BEGIN
-- Check for duplicate ProductName
IF EXISTS (SELECT 1 FROM Products WHERE ProductName = @ProductName)
BEGIN
PRINT 'Duplicate ProductName exists';
RETURN;
END
INSERT INTO Products (ProductName, Address, Country, State, City, ProductionDocument)
SELECT SCOPE_IDENTITY() AS NewProductId;
END;
CREATE PROCEDURE [dbo].[sp_UpdateProduct]
@Id INT,
@ProductName NVARCHAR(255),
@Address NVARCHAR(255) = NULL,
@Country NVARCHAR(255),
@State NVARCHAR(255),
@City NVARCHAR(255),
@ProductionDocument NVARCHAR(255) = NULL
AS
BEGIN
-- Check for duplicate ProductName excluding the current record
IF EXISTS (SELECT 1 FROM Products WHERE ProductName = @ProductName AND Id != @Id)
BEGIN
PRINT 'Duplicate ProductName exists';
RETURN;
END
UPDATE Products
SET ProductName = @ProductName,
Address = @Address,
Country = @Country,
State = @State,
City = @City,
ProductionDocument = @ProductionDocument,
CraetedOn = GETDATE()
WHERE Id = @Id;
END;
Tools Used: Visual Studio 2022 and SQL SERVER Management Studio
☕ Buy me a Coffee (Channel Support through Donation)
📻 Recommended Courses
Subscribe to this channel
Must buy Programming Laptops :
Share, Support, Subscribe Now :
⭐️Tags : ⭐️
#dotnetcore
#netcorewebapi
#crudoperations
Thanks for watching. 😊😊 🙏🙏
Комментарии