public static void Save(Customer customer) { using (var connection = DataAccessObject.CreateConnection()) { connection.Open(); string commandString = "INSERT INTO Customer VALUES (@Name, @DateOfBirth, @Country)"; var command = DataAccessObject.CreateCommand(commandString, System.Data.CommandType.Text, connection); command.Parameters.Add(DataParameterHelper.CreateParameter(string.Empty, "@Name", 150, customer.Name, System.Data.DbType.String)); command.Parameters.Add(DataParameterHelper.CreateParameter(string.Empty, "@DateOfBirth", customer.DateOfBirth, System.Data.DbType.Date)); command.Parameters.Add(DataParameterHelper.CreateParameter(string.Empty, "@Country", 150, customer.Country, System.Data.DbType.String)); command.ExecuteNonQuery(); DataAccessObject.CloseConnection(connection); } }
public void Save(Order order, int customerId) { using (var connection = DataAccessObject.CreateConnection()) { connection.Open(); string commandString = "INSERT INTO [Orders] VALUES (@CustomerId, @Amount, @VAT)"; var command = DataAccessObject.CreateCommand(commandString, System.Data.CommandType.Text, connection); command.Parameters.Add(DataParameterHelper.CreateParameter(string.Empty, "@CustomerId", customerId, System.Data.DbType.Int32)); command.Parameters.Add(DataParameterHelper.CreateParameter(string.Empty, "@Amount", order.Amount, System.Data.DbType.Double)); command.Parameters.Add(DataParameterHelper.CreateParameter(string.Empty, "@VAT", order.VAT, System.Data.DbType.Double)); command.ExecuteNonQuery(); DataAccessObject.CloseConnection(connection); } }