Imidacloprid will kill gnats but not through the plant. It affects immature gnats in the soil directly, and only while it persists in the soil. I have already explained how insecticidal soap can be used, in much the same way but more harmless to the environment.