By Maricic Sinisa private int SaveCustomer (string firstName , string lastName , string email, string address) { using ( SqlConnection connection = new SqlConnection ( connectionString )) { // Check if customer with the same email already exists string checkQuery = "SELECT CustomerID FROM Customer WHERE Email = @Email"; SqlCommand checkCommand = new SqlCommand ( checkQuery , connection); checkCommand.Parameters.AddWithValue ("@Email", email); connection.Open (); object existingCustomerId = checkCommand.ExecuteScalar (); if ( existingCustomerId != null) // Customer already exists { return Convert.ToInt32( existingCustomerId ); } else // Customer does not exist, insert new record { string insertQuery = "INSERT INTO Customer (FirstName, LastName , Email, Address) VALUES (@FirstName, @LastName, @Email, @Address); SELECT SCOPE_IDENTITY();"; SqlCommand insertCommand = new SqlCommand ( insertQuery , connection); insertCommand.Parameters.AddWithValue ("@FirstName", firstName ); insertCommand.Parameters.AddWithValue ("@ LastName ", lastName ); insertCommand.Parameters.AddWithValue ("@Email", email); insertCommand.Parameters.AddWithValue ("@Address", address); // Execute insert command and return newly generated CustomerID return Convert.ToInt32( insertCommand.ExecuteScalar ()); } } } private int SaveProduct (string productName ) { using ( SqlConnection connection = new SqlConnection ( connectionString )) { string query = "INSERT INTO Product (ProductName) VALUES (@ProductName); SELECT SCOPE_IDENTITY();"; SqlCommand command = new SqlCommand (query, connection); command.Parameters.AddWithValue ("@ProductName", productName ); connection.Open (); return Convert.ToInt32( command.ExecuteScalar ()); } } private void SaveQuantity (int customerId , int productId , int quantity) { using ( SqlConnection connection = new SqlConnection ( connectionString )) { string query = "INSERT INTO OrderDetails ( CustomerID , ProductID , Quantity) VALUES (@CustomerID, @ProductID, @Quantity);"; SqlCommand command = new SqlCommand (query, connection); command.Parameters.AddWithValue("@CustomerID", customerId); command.Parameters.AddWithValue ("@ ProductID ", productId ); command.Parameters.AddWithValue ("@ Quantity ", quantity ); connection.Open (); command.ExecuteNonQuery (); } } } } C-Sharp code mechanism to operate the program