Couple of ways:
- If your barcodes always have the same length, wait until the text in the textbox has the right length.
- Configure your scanner to send a special suffix which will allow you to identify the end of the code.
- Start a timer when the first char is entered with a timeout that is sufficiently larger than the delay between single chars sent by the scanner and reset the timer each time another char gets appended. Then only start your database query when the timer has elapsed - that is, after the text hasn't changed for the specified timer interval.
- Don't use a textbox at all but read the barcode scanner's transmission directly at a lower API level - which is what I would do. See here:
Using Raw Input from C# to handle multiple keyboards[
^] (A typical barcode scanner is basically a keyboard from the system's point of view.)