using System.Data.SqlClient; using OpenCBS.CoreDomain; using OpenCBS.ExceptionsHandler.ExceptionHandlers; using OpenCBS.ExceptionsHandler.Exceptions.ContractExceptions; public void InsertLoanProduct(LoanProduct product) { using (var connection = new SqlConnection(connectionString)) { connection.Open(); using (var command = new OpenCbsCommand($"INSERT INTO LoanProducts (Name, InterestRate) VALUES ('{product.Name}', {product.InterestRate})", connection)) { try { command.ExecuteNonQuery(); } catch (Exception ex) { throw new OpenCbsContractSaveException(ex.Message, ex); } } } }
using System.Data.SqlClient; using OpenCBS.CoreDomain; using OpenCBS.ExceptionsHandler.ExceptionHandlers; using OpenCBS.ExceptionsHandler.Exceptions.ContractExceptions; public void DeleteLoanProduct(int productId) { using (var connection = new SqlConnection(connectionString)) { connection.Open(); using (var command = new OpenCbsCommand($"DELETE FROM LoanProducts WHERE Id = {productId}", connection)) { try { command.ExecuteNonQuery(); } catch (Exception ex) { throw new OpenCbsContractSaveException(ex.Message, ex); } } } }This example shows how to delete a loan product from the database using the ExecuteNonQuery method. The method opens a connection to the database, creates an OpenCbsCommand with the SQL DELETE query, and executes it by calling ExecuteNonQuery. If the query fails, it catches the exception and throws a custom OpenCbsContractSaveException. Package library: OpenCBS.CoreDomain